首页 > 系统 > Linux > 正文

Linux OpenCV 静态链接错误

2024-06-28 13:19:53
字体:
来源:转载
供稿:网友
linux OpenCV 静态链接错误

错误一:

undefined reference to `dlopen'

undefined reference to `dlerror'

undefined reference to `dlsym'

对dlopen, dlerror, dlsym 未定义的引用, 缺少链接库, 链接时加上选项 -ldl

参考:

  1. http://blog.csdn.net/houjixin/article/details/8624581
  2. http://stackoverflow.com/questions/29557683/undefined-reference-to-symbol-dlsymglibc-2-4

错误二:

对icvPuts, icvGets 未定义的引用,编译错误如下:

./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvPuts(CvFileStorage*, char const*)':persistence.cpp:(.text._ZL7icvPutsP13CvFileStoragePKc+0x20): undefined reference to `gzputs'./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvGets(CvFileStorage*, char*, int)':persistence.cpp:(.text._ZL7icvGetsP13CvFileStoragePci+0x26): undefined reference to `gzgets'./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvxmlSkipSpaces(CvFileStorage*, char*, int)':persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x1e2): undefined reference to `gzgets'persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x208): undefined reference to `gzeof'persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x33c): undefined reference to `gzeof'./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `_ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3':persistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x124): undefined reference to `gzgets'persistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x170): undefined reference to `gzeof'/cygdrive/d/soft/NVPACK/android-ndk-r7c/build/core/build-binary.mk:366: recipe for target `obj/local/armeabi-v7a/libnative-activity.so' failedpersistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x28e): undefined reference to `gzeof'./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `cvReleaseFileStorage':persistence.cpp:(.text.cvReleaseFileStorage+0x24): undefined reference to `gzclose'./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `cvOpenFileStorage':persistence.cpp:(.text.cvOpenFileStorage+0x66e): undefined reference to `gzopen'persistence.cpp:(.text.cvOpenFileStorage+0x8fc): undefined reference to `gzclose'persistence.cpp:(.text.cvOpenFileStorage+0xaea): undefined reference to `gzrewind'persistence.cpp:(.text.cvOpenFileStorage+0xbee): undefined reference to `gzrewind'persistence.cpp:(.text.cvOpenFileStorage+0xc0a): undefined reference to `gzclose'collect2: ld returned 1 exit status

缺少zlib库引起的, 编译链接时加上 -lz

参考:

  1. http://stackoverflow.com/questions/10858055/opencv2-4-with-android-native-activity

总结: 类似的未定义的引用错误,应该都是由于缺少库的原因引起的, 静态链接OpenCV库的时候, 不仅需要链接libopencv_***.a, 也需要 dl, zlib 等库, 出现类似错误时, 直接Google 未定义引用的函数对应的库, 然后在链接中添加上.


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表