你的位置:首页 > 操作系统

[操作系统]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 `icv

 

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

参考:

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

 

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