Makefile 产生未定义的引用
Posted
技术标签:
【中文标题】Makefile 产生未定义的引用【英文标题】:Makefile produces undefined references 【发布时间】:2015-08-11 07:07:14 【问题描述】:我收到以下错误:
//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】:链接时库的顺序很重要,应该是反向依赖顺序。所以如果库 B 依赖于库 A,那么在链接时需要将 B 放在 A 之前。
在您的情况下,smfitting
库似乎依赖于 OpenCV 库之一以及其他一些库,因此您需要将其放在这些库之前。
【讨论】:
感谢您解决了所有问题!有没有办法构建库,所以它们不需要那种类型的依赖解析?以上是关于Makefile 产生未定义的引用的主要内容,如果未能解决你的问题,请参考以下文章