对某些 OpenCV 函数的未定义引用

undefined reference to some of the opencv functions

本文关键字:未定义 引用 函数 OpenCV      更新时间:2023-10-16

我正在尝试编译 Ubuntu 14.04 环境中 opencv 示例附带的'motemple.c'。我认为opencv已经正确安装;大多数程序都按预期运行。但是,在编译上述文件时,会为多个函数引发错误"未定义的引用"。以下是编译的输出:

Building target: ACTION_detection1
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "ACTION_detection1"  ./opencvexample/MotionSegmentation.o   -lopencv_core -lopencv_photo -lopencv_videoio -lopencv_videostab -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
./opencvexample/MotionSegmentation.o: In function `update_mhi':
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:103: undefined reference to `cvUpdateMotionHistory'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:105: undefined reference to `cvUpdateMotionHistory'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:114: undefined reference to `cvCalcMotionGradient'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:123: undefined reference to `cvSegmentMotion'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:149: undefined reference to `cvCalcGlobalOrientation'
collect2: error: ld returned 1 exit status
make: *** [ACTION_detection1] Error 1

可以看出,我已经将所有opencv库链接到mu Eclipse项目。我也尝试了此处提供的命令行解决方案,但仍然收到相同的错误。

它们已从主存储库替换为opencv_contrib。您可以在optflow模块中找到它们。

注意:cvUpdateMotionHistorycvCalcMotionGradient等是OpenCV 1.x API函数的名称,它们现在已经过时/过时,所以尽量通过替换为cv::updateMotionHistorycv::calcMotionGradient等来避免它们。