对gtest中的testing :: internal :: EqFailure的未定义引用

 炫彩十字绣I_775 发布于 2023-01-02 12:24

我正在尝试使用GoogleTest对函数进行测试,现在它不再找到了这个EqFailure 东西:

/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 

#include "tools/CMorphology.hpp"

TEST(erode_Morph, crossKernel_Morph)
{
  // initialize matrix to be eroded
  cv::Mat matrix = (cv::Mat_(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_(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(i)[j], verMat.ptr(i)[j]);
    }
  }
}

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

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
         )

我之前已经做过这个,并且在一些提交之后它显示了这个错误.为什么它不再找到它?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有