Makefile生成未定义的引用

时间:2015-08-11 07:07:14

标签: c++ linux makefile gnu-make

我收到以下错误:

//usr/local/lib/libsmfitting.so: undefined reference to `VO_FaceParts::VO_GetOneFacePart(unsigned int) const'
//usr/local/lib/libsmfitting.so: undefined reference to `cv::estimateRigidTransform(cv::_InputArray const&, cv::_InputArray const&, bool)'
collect2: error: ld returned 1 exit status

从这个makefile生成:

Cxx=g++
CXXFLAGS = -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/local/include/vosm/smfitting -I/usr/local/include/vosm/smbuilding -I/usr/local/include/vosm/comalgs -I/usr/local/include/vosm/cvcommon -I/usr/local/include/vosm/ensembletraining -I/usr/local/include/vosm/featureextraction -I/usr/local/include/vosm/integraltransform -I/usr/local/include/vosm/utils
LIBS = -lopencv_ml -lopencv_calib3d -lopencv_legacy -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_video -lopencv_objdetect -lcomalgs -lcvcommon -lensembletraining -lfeatureextraction -lintegraltransform -lsmbuilding -lutils -lboost_system -lboost_filesystem -lsmfitting

all: faceApp.cpp
    $(Cxx) -o faceApp faceApp.cpp $(CXXFLAGS) $(LIBS)

代码看起来是正确的,并且库看起来是正确构建的,我相信错误在于makefile。

1 个答案:

答案 0 :(得分:3)

链接时库的顺序很重要,并且应该是反向依赖顺序。因此,如果库B依赖于库A,则需要在链接时将B放在A之前。

在你的情况下,似乎smfitting库依赖于一个OpenCV库以及一些其他库,所以你需要把它放在那些库之前。