在CMake中OpenCV和Gtest冲突
OpenCV and Gtest conflict in CMake
我正试图在我的应用程序上做一些谷歌测试,我遇到了OpenCV
和GTest
之间的一些冲突:
/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libgtest.a(gtest-all.cc.o): In function `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)':
gtest-all.cc:(.text+0xdd84): multiple definition of `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/local/lib/libopencv_ts.a(ts_gtest.cpp.o):ts_gtest.cpp:(.text._ZN7testing8internal8GTestLogC2ENS0_16GTestLogSeverityEPKci+0x0): first defined here
...
GTest
在opencv_ts
库中使用。有人知道如何解决这些多重定义吗?
我认为,如果我只添加我从OpenCV
使用的库,它将被解决,但我不知道如何做到这一点。我试过了:
target_link_libraries(${Exec8name}_test ${OpenCV}/opencv_core.so* ... )
target_link_libraries(${Exec8name}_test ${OpenCV_LIBS}/opencv_core.so* ... )
target_link_libraries(${Exec8name}_test ${OpenCV_LIBS_DIR}/opencv_core.so* ... )
等,但我得到的只是错误没有找到或No rule to make tarket
我试图删除其中一个,但我得到
的错误/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
...
这是我的CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
option(test "Build all tests." OFF)
set(EXECUTABLE_NAME MyProj)
project(${EXECUTABLE_NAME})
set(CMAKE_CXX_FLAGS "-g -Wall")
include_directories( src/main/cpp
${Boost_INCLUDE_DIRS}
)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem
system
regex
program_options)
add_executable(${EXECUTABLE_NAME}_Sol2
src/main/cpp/main.cpp
src/main/cpp/solution2/MySol2.hpp
src/main/cpp/solution2/MySol2.cpp
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2 ${OpenCV_LIBS}
${Boost_LIBRARIES}
)
if (test)
find_package(GTest REQUIRED)
enable_testing()
include_directories( ${GTEST_INCLUDE_DIRS} )
add_executable(${EXECUTABLE_NAME}_Sol2_test
src/test/cpp/test_Sol2.cpp
src/main/cpp/solution2/MySol2.hpp
src/main/cpp/solution2/MySol2.cpp
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2_test ${OpenCV_LIBRARIES}
${Boost_LIBRARIES}
)
target_link_libraries(${EXECUTABLE_NAME}_Sol2_test ${GTEST_LIBRARIES}
pthread
)
add_test(${EXECUTABLE_NAME}_Sol2_test
${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_NAME}_Sol2_test
)
endif()
谁能告诉我一些方法来解决它?
"opencv_ts"模块包含gtest,所以你可以只包括所需的OpenCV模块排除"ts"模块而不是所有。例如:
find_package(OpenCV REQUIRED core imgproc highgui)
添加我需要的lib,比如
target_link_libraries(${EXECUTABLE_NAME}_Sol2 opencv_core
opencv_highgui
opencv_imgproc
...
)
相关文章:
- 写入位置0x0000000C时发生访问冲突
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- 在gtest.中使用fff.h模拟系统API
- 链表中写入访问冲突的未知原因
- C++中的openCV Mat访问冲突
- 如何使 std::sort 在 std::swap 和我的命名空间的模板化交换之间没有名称冲突?
- C++尝试深度复制唯一指针时出现内存访问冲突
- 错误:使用通用引用的声明冲突
- 如何解决GTest和LibTorch联动冲突
- 如何将GTest与CMake一起使用?遵循谷歌指南时的链接问题
- 两个运营商的一些奇怪的冲突<<
- 如何在多个线程中创建 QSql数据库连接时防止名称冲突
- C++ 中动态二维数组的访问冲突
- 在 gtest 中初始化堆栈上的引用变量的隔离错误
- 从嵌套循环中的 std::list 中删除将返回访问冲突
- CMake与多个gtest冲突
- 在CMake中OpenCV和Gtest冲突