![如何向这个特定的 Makefile 中添加必要的库?](https://linux22.com/image/895101/%E5%A6%82%E4%BD%95%E5%90%91%E8%BF%99%E4%B8%AA%E7%89%B9%E5%AE%9A%E7%9A%84%20Makefile%20%E4%B8%AD%E6%B7%BB%E5%8A%A0%E5%BF%85%E8%A6%81%E7%9A%84%E5%BA%93%EF%BC%9F.png)
我正在尝试运行一些需要 openCV 的代码。问题是,要编译此代码并添加我需要的特定 openCV 功能,我必须将这些库添加到给定的 Makefile 中。我知道当通过命令行编译我的 openCV 代码时,我只需执行
g++ opencv.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -o opencv
(或者也有些轻微的变化)
现在我有了这个 Makefile,但我有点不知道到底需要添加什么
-lopencv_core -lopencv_imgproc -lopencv_highgui
我猜测这三者中的一些可能已经联系在一起,但不是全部。
有人能帮我吗?
有问题的 Makefile:http://paste.ubuntu.com/25192259/或者我应该修改原始的 CMakeLists.txt 文件?
来源:https://github.com/patrikhuber/eos
谢谢!
编辑:
实际上,由于某种原因,它找不到这些库。当我编译代码时,我收到一堆链接错误“未定义引用 xyz”。因为我需要以某种方式添加这 3 个库。每当我为另一个项目编写 openCV 代码时,我总是从命令行编译它并手动添加所有依赖项/库/...。
到目前为止,我还尝试使用以下命令修改 CMakeCache.txt:
cmake -DCMAKE_EXE_LINKER_FLAGS="-lopencv_core -lopencv_imgproc -lopencv_highgui" ../eos
结果:
yalishanda@yalishanda-thinkpad-x200:~/Desktop/John/1/2/software/computerVision/myTests/2/build$ cmake -DCMAKE_EXE_LINKER_FLAGS="-lopencv_core -lopencv_imgproc -lopencv_highgui" ../eos
cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by cmake)
-- Options:
-- EOS_BUILD_EXAMPLES: ON
-- EOS_BUILD_CERES_EXAMPLE: OFF
-- EOS_BUILD_UTILS: OFF
-- EOS_BUILD_DOCUMENTATION: OFF
-- EOS_GENERATE_PYTHON_BINDINGS: OFF
-- EOS_GENERATE_MATLAB_BINDINGS: OFF
-- Found OpenCV: /usr/local (found version "3.2.0") found components: core
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- system
-- Boost found at /usr/include
-- Eigen3 found: TRUE, version: 3.3.3
-- Eigen3 include dir found at /home/yalishanda/Desktop/John/1/2/software/computerVision/myTests/2/eos/3rdparty/eigen
-- OpenCV 3.x detected - including imgcodecs for compatibility
-- Found OpenCV: /usr/local (found suitable version "3.2.0", minimum required is "3") found components: core imgproc imgcodecs
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- program_options
-- Boost found at /usr/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yalishanda/Desktop/John/1/2/software/computerVision/myTests/2/build
yalishanda@yalishanda-thinkpad-x200:~/Desktop/John/1/2/software/computerVision/myTests/2/build$ make
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
[ 25%] Linking CXX executable myFaceFit
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
CMakeFiles/myFaceFit.dir/myFaceFit.cpp.o: In function `main':
myFaceFit.cpp:(.text+0x20da): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
myFaceFit.cpp:(.text+0x2102): undefined reference to `cv::waitKey(int)'
collect2: error: ld returned 1 exit status
examples/CMakeFiles/myFaceFit.dir/build.make:100: recipe for target 'examples/myFaceFit' failed
make[2]: *** [examples/myFaceFit] Error 1
CMakeFiles/Makefile2:119: recipe for target 'examples/CMakeFiles/myFaceFit.dir/all' failed
make[1]: *** [examples/CMakeFiles/myFaceFit.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
和
CMAKE_SHARED_LINKER_FLAGS 还有:
$ cmake -DCMAKE_SHARED_LINKER_FLAGS="-lopencv_core -lopencv_imgproc -lopencv_highgui" ../eos
cmake: /home/john/anaconda2/lib/libcurl.so.4: no version information available (required by cmake)
-- Options:
-- EOS_BUILD_EXAMPLES: ON
-- EOS_BUILD_CERES_EXAMPLE: OFF
-- EOS_BUILD_UTILS: OFF
-- EOS_BUILD_DOCUMENTATION: OFF
-- EOS_GENERATE_PYTHON_BINDINGS: OFF
-- EOS_GENERATE_MATLAB_BINDINGS: OFF
-- Found OpenCV: /usr/local (found version "3.2.0") found components: core
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- system
-- Boost found at /usr/include
-- Eigen3 found: TRUE, version: 3.3.3
-- Eigen3 include dir found at /home/yalishanda/Desktop/john/1/2/software/computerVision/myTests/2/eos/3rdparty/eigen
-- OpenCV 3.x detected - including imgcodecs for compatibility
-- Found OpenCV: /usr/local (found suitable version "3.2.0", minimum required is "3") found components: core imgproc imgcodecs
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- program_options
-- Boost found at /usr/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yalishanda/Desktop/john/1/2/software/computerVision/myTests/2/build
yalishanda@yalishanda-thinkpad-x200:~/Desktop/john/1/2/software/computerVision/myTests/2/build$ make
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
[ 25%] Linking CXX executable myFaceFit
/usr/bin/cmake: /home/yalishanda/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
CMakeFiles/myFaceFit.dir/myFaceFit.cpp.o: In function `main':
myFaceFit.cpp:(.text+0x20da): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
myFaceFit.cpp:(.text+0x2102): undefined reference to `cv::waitKey(int)'
collect2: error: ld returned 1 exit status
examples/CMakeFiles/myFaceFit.dir/build.make:100: recipe for target 'examples/myFaceFit' failed
make[2]: *** [examples/myFaceFit] Error 1
CMakeFiles/Makefile2:119: recipe for target 'examples/CMakeFiles/myFaceFit.dir/all' failed
make[1]: *** [examples/CMakeFiles/myFaceFit.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2