CMake中的OpenCV和Gtest冲突 [英] OpenCV and Gtest conflict in CMake
问题描述
我正在尝试对我的应用程序进行一些Google测试,并且遇到了 OpenCV
和 GTest
之间的一些冲突:
I am trying to do some Google Tests on my application and I met some conflicts between OpenCV
and 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
库中使用.有谁知道如何解决这些多个定义?
The GTest
is used in opencv_ts
library. Does anyone kows how to resolve these multiple deinitions?
我认为,如果仅添加从 OpenCV
中使用的库,它将得到解决,但是我不知道该怎么做.我已经尝试过:
I think that if I add just the libraries that I use from OpenCV
it will be resolved, but I do not know how to do this. I have tried:
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* ... )
等,但是我只会得到未找到的错误,或者没有规则可做目标码
etc, but I get just errors of not found or No rule to make tarket
我尝试删除两者之一,但出现
I have tried to remove one of the two, but I get errors of
/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
This is my 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()
有人可以告诉我一些解决方法吗?
Can anyone tell me some ways to fix it?
推荐答案
"opencv_ts"模块包含gtest,因此您可以包括所有必需的OpenCV模块,而"ts"模块除外.例如:
The "opencv_ts" module contains gtest, so you could just include the required OpenCV modules excluded "ts" module insted of all. For example:
find_package(OpenCV REQUIRED core imgproc highgui)
这篇关于CMake中的OpenCV和Gtest冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!