在gtest中未定义对test :: internal :: EqFailure的引用 [英] undefined reference to testing::internal::EqFailure in gtest

查看:1414
本文介绍了在gtest中未定义对test :: internal :: EqFailure的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GoogleTest对某个功能进行测试,但现在找不到EqFailure

I am trying to do a test for a function using GoogleTest an now it is not finding anymore the EqFailure thing:

/usr/include/gtest/gtest.h:1337: undefined reference to `testing::internal::EqFailure(char const*, char const*, testing::internal::String const&, testing::internal::String const&, bool)'

我正在这样编写测试:

test_file.cpp :

#include <gtest/gtest.h>

#include "tools/CMorphology.hpp"

TEST(erode_Morph, crossKernel_Morph)
{
  // initialize matrix to be eroded
  cv::Mat matrix = (cv::Mat_<uchar>(5, 5) << 1, 1, 1, 1, 1,
                                             1, 1, 0, 1, 1,
                                             1, 1, 1, 1, 1,
                                             1, 0, 1, 1, 1,
                                             1, 1, 1, 1, 1
            );
  // initialize the cross kernel
  cv::Mat kernel = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
  // initialize the vector expected as output
  cv::Mat verMat = (cv::Mat_<uchar>(5, 5) << 1, 1, 0, 1, 1,
                                             1, 0, 0, 0, 1,
                                             1, 0, 0, 1, 1,
                                             0, 0, 0, 1, 1,
                                             1, 0, 1, 1, 1);

  // call erode(...)
  Morphology morphology;
  cv::Mat matrixOut;
  morphology.erode(matrix, kernel, matrixOut);

  for (int i = 0; i < matrixOut.rows; i++)
  {
    for (int j = 0; j < matrixOut.rows; j++)
    {
      EXPECT_EQ(matrixOut.ptr<uchar>(i)[j], verMat.ptr<uchar>(i)[j]);
    }
  }
}

我正在使用OpenCV,如果需要,我将发布其他文件.

I am using OpenCV and if needed, I'll post the other files.

CMake文件在这里:

cmake_minimum_required(VERSION 2.8)

set(EXECUTABLE_NAME lpdetect)
project(${EXECUTABLE_NAME})

option(DEBUG "Display images for each step" OFF)

if (DEBUG)
        set(CMAKE_CXX_FLAGS "-g -Wall -Wno-unknown-pragmas -Wno-reorder -Wno-sign-compare -Wno-switch -std=gnu++11 -DDISPLAY_IMGS -DBOOST_LOG_DYN_LINK")
else()
        set(CMAKE_CXX_FLAGS "-g -Wall -Wno-unknown-pragmas -Wno-reorder -Wno-sign-compare -Wno-switch -std=gnu++11 -DBOOST_LOG_DYN_LINK")
endif()

find_package(OpenCV REQUIRED core
                             imgproc
                             features2d
                             nonfree
                             highgui
                             )

find_package(Boost REQUIRED COMPONENTS filesystem
                                       program_options
                                       system
                                       thread
                                       locale
                                       regex
                                       date_time
                                       log
                                       log_setup
                                       timer
                                       )

include_directories(src/main/cpp
                    ${Boost_INCLUDE_DIRS}
                    ${OpenCV2_INCLUDE_DIRS}
                    )

add_executable( ${EXECUTABLE_NAME}
                             src/main/cpp/main.cpp
# and the other files
                             )

target_link_libraries(${EXECUTABLE_NAME} ${OpenCV_LIBS}
                                         "-laws-cpp"
                                         "-lcasablanca"
                                         ${Boost_LIBRARIES}
                                         "-lcrypto"
                                         )


find_package(GTest REQUIRED gtest_main
                            pthread)

enable_testing()

include_directories( ${GTEST_INCLUDE_DIRS} )

add_executable(${EXECUTABLE_NAME}_test src/test/cpp/test_Morphology.cpp
                                       src/main/cpp/tools/CMorphology.cpp
                                       src/main/cpp/tools/CMorphology.hpp
                       )

target_link_libraries(${EXECUTABLE_NAME}_test
                                       ${OpenCV_LIBRARIES}
                                       ${Boost_LIBRARIES}
                                       ${GTEST_LIBRARIES}
                                       )

add_test(${EXECUTABLE_NAME}_test
         ${EXECUTABLE_NAME}_test
         )

我早就做了一个错事,在提交了一些东西之后它显示了这个错误.为什么它找不到了?

I have done this a wile ago, and after some commits it is displaying this error. Why does it no longer find that?

推荐答案

在以下情况下,我已经收到了此错误消息:

I've had exactly this error message in the following scenario:

使用凌乱的Ubuntu 14.10(在libgtest-dev(GTest 1.6)和google-mock(GMock 1.7和捆绑的GTest 1.7之间)不匹配,我选择了错误的路径-安装了GMock 1.6,以匹配系统的libgtest-dev).

Using a messy Ubuntu 14.10 (which has a mismatch between libgtest-dev (GTest 1.6), and google-mock (GMock 1.7 with bundled GTest 1.7), I chose the wrong path - installed GMock 1.6, to match the system's libgtest-dev).

一段时间后,项目进行了编译,但是-在进行git pull之后,使用了1.7的一些新功能,我需要升级到1.7.我从google-mock软件包(用CMake重建,然后复制到/usr/include/usr/lib)安装了它.然后,我启动了构建,并且gtest.h:1337(此行号不是在告诉吗?)链接器错误开始发生.

For some time the project compiled, but then - after a git pull, some new features of 1.7 were used and I needed to upgrade to 1.7. I installed it from google-mock package (rebuilt with CMake, then copied to /usr/include and /usr/lib). Then, I launched the build, and the gtest.h:1337 (isn't this line number telling?) linker error started happening.

经过数小时的nm -C libgtest.a检查库(重复libgtest_main.alibgmock.alibgmock_main.a)后,我发现testing::internal::EqFailure函数需要2x std::string,而不是testing::internal::String. !

After hours of inspecting the libs with nm -C libgtest.a (repeat for libgtest_main.a, libgmock.a and libgmock_main.a), I found that the testing::internal::EqFailure function takes 2x std::string, and not testing::internal::String.!!

我检查了标头-那里什么都没有-std::string到处都是.奇怪的参考在哪里?

I checked the headers - nothing there - std::string everywhere. Where was the strange reference?

好吧-它在旧的目标文件中,使用GTest 1.6标头构建!所以现在:

Well - it was in the old object files, build with GTest 1.6 headers! So now:

TL; DR

  • 删除并重建使用GTest 1.6标头构建的所有旧对象. (make clean,或类似的意思,YMMV)
  • 如果没有,请升级GMock.
  • 如果没有,请仅使用捆绑的GTest(来自GMock).
  • Remove and rebuild all old objects which you built with GTest 1.6 headers. (make clean, or something to that effect, YMMV)
  • Upgrade GMock, if you haven't.
  • Use only bundled GTest (from GMock), if you haven't.

这篇关于在gtest中未定义对test :: internal :: EqFailure的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆