我在/ usr / local / lib中安装了OpenCV2.4.0的副本
我的程序编译正确,但是当引发链接器时,它会产生错误,例如:
/home/zhouw/moos-ivp-zhouw/trunk/src/pATRTest/mst.cpp:661: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat const&)'
CMakeFiles/pATR.dir/mst.cpp.o:/home/zhouw/moos-ivp-zhouw/trunk/src/pATRTest/mst.cpp:675: more undefined references to `cv::_OutputArray::_OutputArray(cv::Mat const&)'
collect2: ld returned 1 exit status
make[2]: *** [../bin/pATR] Error 1
make[1]: *** [src/pATRTest/CMakeFiles/pATR.dir/all] Error 2
make: *** [all] Error 2
奇怪的是我的程序密集使用opencv,如果CMake无法找到库,它应该抱怨比jsut更多的未定义引用 .
我尝试在我的cmake文件中添加LINK_DIRECTORIES(“/ usr / local / lib”)但它没有帮助 . 在/ usr / local / lib下还安装了另一个名为POCO的库 . 我的程序也链接到POCO库,但CMake似乎没有找到它们 .
如果我手动链接-L / usr / local / lib,它将正确链接而不会出错 .
CMakeLists.txt看起来像这样
PROJECT(pATR)
#what files are needed?
SET(SRCS
spline.hpp
utils.hpp utils.cpp
mst.hpp mst.cpp
cluster.hpp cluster.cpp
target.hpp target.cpp
detector.hpp detector.cpp
classifier.hpp classifier.cpp
atr.hpp atr.cpp
MOOSAtr.h MOOSAtr.cpp
main.cpp
)
ADD_EXECUTABLE(pATR ${SRCS})
# indicate how to link
#LINK_DIRECTORIES("/usr/local/lib")
TARGET_LINK_LIBRARIES(pATR opencv_core opencv_highgui opencv_imgproc MOOS)
INSTALL(TARGETS
pATR
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)
知道发生了什么事吗?非常感谢!
3 回答
如果您有CMake 2.8,我建议使用
find_package(OpenCV)
来加载库 .在http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html有一个例子
CMake文件:
我不确定CMake是否无法找到链接库 . CMake找到你的依赖项并生成Makefile,但它实际上并没有为你编译和链接 .
你的错误不是来自CMake,对吧?他们来自制造 .
我总是手动链接这个
在调用g时 .
你是在追求:
来自文档:
另外,有关详细信息,请查看以下链接 .
https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-To-Find-Libraries