CMake与OpenCV库的链接错误
我正在做一个项目,它使用我的包管理器上的OpenCV开发库。我目前正在使用两台机器来完成这个项目,我的笔记本电脑和台式机。当我在笔记本电脑上编译代码时,我没有任何问题。然而,我的桌面上出现了一个链接错误,这很奇怪,因为两台机器都有所有相应的库 错误消息抱怨对一组应该链接但找不到的方法的未定义引用。以下是cmake和make的输出: cmake:CMake与OpenCV库的链接错误,opencv,makefile,g++,cmake,vtable,Opencv,Makefile,G++,Cmake,Vtable,我正在做一个项目,它使用我的包管理器上的OpenCV开发库。我目前正在使用两台机器来完成这个项目,我的笔记本电脑和台式机。当我在笔记本电脑上编译代码时,我没有任何问题。然而,我的桌面上出现了一个链接错误,这很奇怪,因为两台机器都有所有相应的库 错误消息抱怨对一组应该链接但找不到的方法的未定义引用。以下是cmake和make的输出: cmake: malak@bigblackbox:~/Dropbox/libcardreader/release$ cmake .. && make
malak@bigblackbox:~/Dropbox/libcardreader/release$ cmake .. && make
-- The C compiler identification is GNU 4.7.2
-- The CXX compiler identification is GNU 4.7.2
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/malak/Dropbox/libcardreader/release
制作:
libimganalyzer.cpp
有一个#include
语句引用libimganalyzer.h
,下面是我在libimganalyzer.h
中引用的内容:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
下面是我的CMakeLists.txt
文件的输出:
set( CMAKE_AUTOMOC ON )
cmake_minimum_required(VERSION 2.8)
project( test )
find_package( OpenCV REQUIRED )
add_executable( test test.cpp libimganalyzer.cpp libimganalyzer.h libcardreader.cpp libcardreader.h )
target_link_libraries( test ${OpenCV_LIBS} )
我想知道我的桌面上缺少什么使我可以在笔记本电脑上顺利编译这个项目
更新:我在笔记本电脑和台式机上尝试了多种方案,包括cmake
和make
,如果有帮助,结果如下:
cmake
桌面<桌面上的code>make:cmake
成功,make
在上面抛出错误
cmake
桌面<在笔记本电脑上编码>制作:cmake
成功,make
成功。项目运行
cmake
在笔记本电脑上<桌面上的code>make:cmake
成功,make
成功。项目运行
cmake
在笔记本电脑上<在笔记本电脑上编码>制作:cmake
成功,make
成功。项目运行。我不确定,但您的电脑中是否有ROS系统,而您的笔记本电脑中没有该系统……我也有类似的问题。我的笔记本电脑上有Debian,桌面上有Crunchbang。这两个版本最初都是amd64体系结构版本,我已经将它们设置为能够通过dpkg
编译i386包。ROS基于Ubuntu,而Ubuntu又基于Debian,因此,如果您有类似的设置,我们的问题可能不会有太大的不同。我在笔记本电脑和PC中使用32位Ubuntu 12.04(精确)。我有ROS hydro。您是否在任何时候将发布目录从笔记本电脑复制到桌面?当您删除发布目录,然后运行cmake/make时,是否会出现相同的错误?Cmake在其缓存中存储有关库的信息,并且很难检测这些库的更改(例如路径或版本)。很抱歉延迟。自从我的文件服务器关闭后,我就使用Dropbox在我的台式机和笔记本电脑之间轻松地共享我的文件cmake
在台式机和笔记本电脑上都能工作,但make
只能正确链接笔记本电脑上的文件。桌面输出与上述相同的错误。我所尝试的将被添加到问题的顶部。
malak@bigblackbox:~/Dropbox/libcardreader/release$ cat /usr/include/opencv2/features2d/features2d.hpp | grep MSER
typedef struct CvMSERParams
/////// the next few params for MSER of color image
} CvMSERParams;
CVAPI(CvMSERParams) cvMSERParams( int delta CV_DEFAULT(5), int min_area CV_DEFAULT(60),
CVAPI(void) cvExtractMSER( CvArr* _img, CvArr* _mask, CvSeq** contours, CvMemStorage* storage, CvMSERParams params );
/////// The class implements MSER algorithm introduced by J. Matas.
class CV_EXPORTS_W MSER : public CvMSERParams
CV_WRAP MSER();
CV_WRAP MSER( int _delta, int _min_area, int _max_area,
//! the operator that extracts the MSERs from the image or the specific part of it
MserFeatureDetector( CvMSERParams params=cvMSERParams() );
MSER mser;
malak@bigblackbox:~/Dropbox/libcardreader/release$
set( CMAKE_AUTOMOC ON )
cmake_minimum_required(VERSION 2.8)
project( test )
find_package( OpenCV REQUIRED )
add_executable( test test.cpp libimganalyzer.cpp libimganalyzer.h libcardreader.cpp libcardreader.h )
target_link_libraries( test ${OpenCV_LIBS} )