error: ld returned 1 exit status
阿新 • • 發佈:2017-09-12
fig 2.4 undefine 一個 去哪裏 安裝 ini set col
[email protected]5437:~/Downloads/LBD_Descriptor/build$ cmake .. -- Configuring done -- Generating done -- Build files have been written to: /home/wj/Downloads/LBD_Descriptor/build [email protected]-Inspiron-5437:~/Downloads/LBD_Descriptor/build$ make [ 66%] Built target LineMatchingLib Linking CXX executable TestLineMatchingAlgorithm CMakeFiles/TestLineMatchingAlgorithm.dir/TestLineMatchingAlgorithm.cpp.o: In function `cv::String::String(char const*)‘: TestLineMatchingAlgorithm.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x30): undefined reference to `cv::String::allocate(unsigned long)‘ CMakeFiles/TestLineMatchingAlgorithm.dir/TestLineMatchingAlgorithm.cpp.o: In function `cv::String::String(std::stringconst&)‘: TestLineMatchingAlgorithm.cpp:(.text._ZN2cv6StringC2ERKSs[_ZN2cv6StringC5ERKSs]+0x34): undefined reference to `cv::String::allocate(unsigned long)‘ CMakeFiles/TestLineMatchingAlgorithm.dir/TestLineMatchingAlgorithm.cpp.o: In function `main‘: TestLineMatchingAlgorithm.cpp:(.text.startup+0xfe): undefined reference to `cv::imread(cv::String const&, int)‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x12a): undefined reference to `cv::String::deallocate()‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x21e): undefined reference to `cv::imread(cv::String const&, int)‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x24a): undefined reference to `cv::String::deallocate()‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x624): undefined reference to `cv::line(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x7f3): undefined reference to `cv::line(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x89d): undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x8a5): undefined reference to `cv::String::deallocate()‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x939): undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0x941): undefined reference to `cv::String::deallocate()‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0xa96): undefined reference to `cv::String::deallocate()‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0xac9): undefined reference to `cv::String::deallocate()‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0xb53): undefined reference to `cv::String::deallocate()‘ TestLineMatchingAlgorithm.cpp:(.text.startup+0xb96): undefined reference to `cv::String::deallocate()‘ libLineMatchingLib.so: undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)‘ libLineMatchingLib.so: undefined reference to `cv::write(cv::FileStorage&, cv::String const&, cv::Mat const&)‘ libLineMatchingLib.so: undefined reference to `cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)‘ libLineMatchingLib.so: undefined reference to `cv::operator<<(cv::FileStorage&, cv::String const&)‘ collect2: error: ld returned 1 exit status make[2]: *** [TestLineMatchingAlgorithm] Error 1 make[1]: *** [CMakeFiles/TestLineMatchingAlgorithm.dir/all] Error 2 make: *** [all] Error 2
閱讀錯誤之後,感覺是opencv本的問題(由於我安裝了兩個版本opencv-2.4.9 and opencv-3.1.0),搜了相關問題,然後修改了CMakeList.txt,解決了此問題。
參考了這個博客:http://www.cnblogs.com/xzd1575/p/5555523.html
CMake下指定Opencv版本
關鍵文件:OpenCVConfig.cmake。在opencv編譯好後,所在目錄中一般會有一個叫OpenCVConfig.cmake的文件,這個文件中指定了CMake要去哪裏找OpenCV,其.h文件在哪裏等.
只要讓CMake找到這個文件,這個文件就指定了Opencv的所有路徑,因此設置OpenCV_DIR為包含OpenCVConfig.cmake的目錄,如在我的C++工程CMakeLists.txt中添加
set(OpenCV_DIR "/home/wj/gxcode/slambook/3rdparty/opencv-3.1.0/build/") //找OpenCVConfig.cmake目錄
註意,將其添加在project(MyProjectName)之前。
如CMakeLists.txt內容如下:
PROJECT(LILIANTESTS) cmake_minimum_required(VERSION 2.8) set(OpenCV_DIR "/home/wj/opencv-3.1.0/build/") find_package( OpenCV REQUIRED ) add_executable( camera camera.cpp ) target_link_libraries( camera ${OpenCV_LIBS} )
error: ld returned 1 exit status