我正在开发一个使用我的包管理器上的OpenCV开发库的项目。我目前正在使用两台机器来处理这个项目,我的笔记本电脑和桌面。当我在笔记本电脑上编译代码时,我没有任何问题。但是,我在桌面上遇到链接错误,这很奇怪,因为两台机器都有相应的库。
错误消息抱怨对应该被链接但未找到的一组方法的未定义引用。这是cmake和make的输出:
cmake的:
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
请:
Scanning dependencies of target test
[ 33%] Building CXX object CMakeFiles/test.dir/test.cpp.o
[ 66%] Building CXX object CMakeFiles/test.dir/libimganalyzer.cpp.o
[100%] Building CXX object CMakeFiles/test.dir/libcardreader.cpp.o
Linking CXX executable test
CMakeFiles/test.dir/libimganalyzer.cpp.o: In function `cv::MSER::~MSER()':
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0xe): undefined reference to `vtable for cv::MSER'
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0x26): undefined reference to `vtable for cv::MSER'
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0x2e): undefined reference to `VTT for cv::MSER'
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0x55): undefined reference to `cv::Algorithm::~Algorithm()'
libimganalyzer.cpp:(.text._ZN2cv4MSERD1Ev[_ZN2cv4MSERD1Ev]+0x8a): undefined reference to `cv::Algorithm::~Algorithm()'
collect2: error: ld returned 1 exit status
make[2]: *** [test] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
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>
如果我使用cat查看features2d.hpp
的内容,这是定义MSER的地方,它会显示:
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$
这是我的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
;桌面上的make
:cmake
成功,make
会抛出错误。
cmake
;笔记本电脑上的make
:cmake
成功,make
成功。项目运行。
cmake
;桌面上的make
:cmake
成功,make
成功。项目运行。
cmake
;笔记本电脑上的make
:cmake
成功,make
成功。项目运行。