[cmake报错]collect2: error: ld returned 1 exit status

在进行CMake编译时出现了如下错误:

[ 50%] Building CXX object CMakeFiles/orbslamTest.dir/testORB.cpp.o
[100%] Linking CXX executable ../orbslamTest
CMakeFiles/orbslamTest.dir/testORB.cpp.o: In function `main':
testORB.cpp:(.text.startup+0x115): undefined reference to `ORB_SLAM3::ORBextractor::ORBextractor(int, float, int, int, int)'
testORB.cpp:(.text.startup+0x378): undefined reference to `ORB_SLAM3::ORBextractor::operator()(cv::_InputArray const&, cv::_InputArray const&, std::vector >&, cv::_OutputArray const&, std::vector >&)'
collect2: error: ld returned 1 exit status
CMakeFiles/orbslamTest.dir/build.make:142: recipe for target '../orbslamTest' failed
make[2]: *** [../orbslamTest] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/orbslamTest.dir/all' failed
make[1]: *** [CMakeFiles/orbslamTest.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

原因:
在编译共享库时,由于ORBextractor.cc代码文件的后缀名与其他文件不一致(其他是.cpp文件),在CMakeLists.txt文件中将.cc代码文件漏掉了,虽然代码测试文件中正确引用了头文件,但是共享库没有包含这部分的源代码,因此在链接该动态库时报错。

你可能感兴趣的:(C++学习笔记,c++)