我尝试编译由GTest,OpenCV,CMake和Make组成的项目(它只是一个脚本)。层次结构是:
.
├── build
├── include
│ ├── csv_loader.h
│ ├── loader.h
│ ├── mat_reader.h
│ ├── processor.h
│ └── reader.h
├── Makefile
├── pictures
│ └── pila_original.jpg
├── sources
│ ├── CMakeLists.txt
│ ├── csv_loader.cpp
│ ├── mat_reader.cpp
│ └── processor.cpp
└── test
├── CMakeLists.txt
├── hello-test.cpp
└── not_null_data-test.cpp
当我尝试编译整个项目时,我在test / CmakeLists.txt中遇到了这个错误:
CMakeFiles/CPOO-PROJECT-TEST.dir/not_null_data-test.cpp.o: In function `NOTNULL_flowtest_Test::TestBody()':
not_null_data-test.cpp:(.text+0x1e): undefined reference to `Processor::Processor()'
not_null_data-test.cpp:(.text+0x2d): undefined reference to `Processor::Detect()'
not_null_data-test.cpp:(.text+0xfb): undefined reference to `Processor::~Processor()'
not_null_data-test.cpp:(.text+0x145): undefined reference to `Processor::~Processor()'
collect2: error: ld returned 1 exit status
./测试/的CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(CPOO-PROJECT-TEST)
find_package( OpenCV 3.1.0 REQUIRED )
#eanble_testing()
find_package( GTest REQUIRED )
add_definitions(-std=c++11)
set (LIB ../release/libCPOO-PROJECT.so)
file(GLOB TEST "*.cpp")
include_directories(../include)
include_directories( ${OpenCV_INCLUDE_DIRS}
${GTest_INCLUDE_DIRS})
add_executable( ${PROJECT_NAME} ${LIB} ${TEST})
target_link_libraries( ${PROJECT_NAME}
${GTEST_BOTH_LIBRARIES}
pthread
)
我不知道如何修复链接器问题,如果需要任何其他信息,我会添加它们。
编辑1 向CMake添加标志后,我得到了这个日志:
Scanning dependencies of target CPOO-PROJECT-TEST
make[3]: Leaving directory '/home/mateusz/Projects/EiTI/CPOO/build/test'
make -f CMakeFiles/CPOO-PROJECT-TEST.dir/build.make CMakeFiles/CPOO-PROJECT-TEST.dir/build
make[3]: Entering directory '/home/mateusz/Projects/EiTI/CPOO/build/test'
[ 33%] Building CXX object CMakeFiles/CPOO-PROJECT-TEST.dir/hello-test.cpp.o
/usr/bin/c++ -I/home/mateusz/Projects/EiTI/CPOO/test/../include -I/usr/include/opencv -std=c++11 -o CMakeFiles/CPOO-PROJECT-TEST.dir/hello-test.cpp.o -c /home/mateusz/Projects/EiTI/CPOO/test/hello-test.cpp
[ 66%] Building CXX object CMakeFiles/CPOO-PROJECT-TEST.dir/not_null_data-test.cpp.o
/usr/bin/c++ -I/home/mateusz/Projects/EiTI/CPOO/test/../include -I/usr/include/opencv -std=c++11 -o CMakeFiles/CPOO-PROJECT-TEST.dir/not_null_data-test.cpp.o -c /home/mateusz/Projects/EiTI/CPOO/test/not_null_data-test.cpp
[100%] Linking CXX executable CPOO-PROJECT-TEST
/usr/bin/cmake -E cmake_link_script CMakeFiles/CPOO-PROJECT-TEST.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/CPOO-PROJECT-TEST.dir/hello-test.cpp.o CMakeFiles/CPOO-PROJECT-TEST.dir/not_null_data-test.cpp.o -o CPOO-PROJECT-TEST -rdynamic -lgtest -lgtest_main -lpthread
CMakeFiles/CPOO-PROJECT-TEST.dir/not_null_data-test.cpp.o: In function `NOTNULL_flowtest_Test::TestBody()':
not_null_data-test.cpp:(.text+0x1e): undefined reference to `Processor::Processor()'
not_null_data-test.cpp:(.text+0x2d): undefined reference to `Processor::Detect()'
not_null_data-test.cpp:(.text+0xfb): undefined reference to `Processor::~Processor()'
not_null_data-test.cpp:(.text+0x145): undefined reference to `Processor::~Processor()'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/CPOO-PROJECT-TEST.dir/build.make:126: CPOO-PROJECT-TEST] Error 1
make[3]: Leaving directory '/home/mateusz/Projects/EiTI/CPOO/build/test'
make[2]: *** [CMakeFiles/Makefile2:71: CMakeFiles/CPOO-PROJECT-TEST.dir/all] Error 2
make[2]: Leaving directory '/home/mateusz/Projects/EiTI/CPOO/build/test'
make[1]: *** [Makefile:87: all] Error 2
make[1]: Leaving directory '/home/mateusz/Projects/EiTI/CPOO/build/test'
make: *** [Makefile:13: build-test] Error 2