仅在使用 -Wl、-rpath、/usr/local/MATLAB/R2014b/bin/glnxa64 添加 Matkab 代码后链接错误 OpenCV

Posted

技术标签:

【中文标题】仅在使用 -Wl、-rpath、/usr/local/MATLAB/R2014b/bin/glnxa64 添加 Matkab 代码后链接错误 OpenCV【英文标题】:Linking error OpenCV only after using a -Wl,-rpath,/usr/local/MATLAB/R2014b/bin/glnxa64 for adding Matkab code 【发布时间】:2015-01-18 18:32:11 【问题描述】:

我已设法在 openCV 站点中运行示例,显示 eclipse 中的图像 (http://docs.opencv.org/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html)

我有另一个项目,我从 mat 文件中读取了一些矩阵,当我尝试将两者合并以显示从 mat 文件中读取的图像时,会显示以下错误:

19:09:59 **** Incremental Build of configuration Debug for project testMAT ****
make all 
Building file: ../src/testMAT.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/MATLAB/R2014b/extern/include -I/usr/include/opencv -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testMAT.d" -MT"src/testMAT.d" -o "src/testMAT.o" "../src/testMAT.cpp"
../src/testMAT.cpp: In function ‘int diagnose(const char*, const char*)’:
../src/testMAT.cpp:70:43: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
   printf("the size of c is %u\n", sizeof c);
                                           ^
../src/testMAT.cpp:78:10: warning: unused variable ‘mrows’ [-Wunused-variable]
   mwSize mrows = mxGetM(fPtr);
          ^
../src/testMAT.cpp:79:10: warning: unused variable ‘ncols’ [-Wunused-variable]
   mwSize ncols = mxGetN(fPtr);
          ^
../src/testMAT.cpp:38:16: warning: unused variable ‘dir’ [-Wunused-variable]
   const char **dir;
                ^
../src/testMAT.cpp:39:22: warning: unused variable ‘nome’ [-Wunused-variable]
   const char *name, *nome;
                      ^
../src/testMAT.cpp:40:9: warning: unused variable ‘ndir’ [-Wunused-variable]
   int   ndir;
         ^
../src/testMAT.cpp:41:9: warning: unused variable ‘i’ [-Wunused-variable]
   int   i;
         ^
../src/testMAT.cpp:57:10: warning: variable ‘nElements’ set but not used [-Wunused-but-set-variable]
   mwSize nElements;       /* number of elements in array */
          ^
../src/testMAT.cpp:60:11: warning: unused variable ‘realPtr’ [-Wunused-variable]
   double *realPtr;        /* pointer to data */
           ^
../src/testMAT.cpp:61:10: warning: variable ‘total’ set but not used [-Wunused-but-set-variable]
   double total;           /* value to calculate */
          ^
Finished building: ../src/testMAT.cpp

**Building target: testMAT
Invoking: GCC C++ Linker
g++  -Wl,-rpath,/usr/local/MATLAB/R2014b/bin/glnxa64 -L/usr/local/MATLAB/R2014b/bin/glnxa64 -L/usr/lib/x86_64-linux-gnu -o "testMAT"  ./src/testMAT.o   -leng -lmat -lmex -lut -lmx -lopencv_core -lopencv_imgproc -lopencv_highgui
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFGetField@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFReadEncodedTile@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFReadRGBATile@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFClose@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFRGBAImageOK@LIBTIFF_4.0'
makefile:45: recipe for target 'testMAT' failed
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFOpen@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFSetField@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
collect2: error: ld returned 1 exit status
make: *** [testMAT] Error 1 **

19:10:00 Build Finished (took 810ms)

当我只添加 -Wl、-rpath、/usr/local/MATLAB/R2014b/bin/glnxa64,而不向源文件添加任何代码时,即使在 opencv 示例中也会显示此错误。 没有标志,一切正常。

如何将 matlab 代码包含到这个 opencv 项目中?

【问题讨论】:

看起来您在 opencv_highgui 中有未定义的对 libtiff 函数的引用。我认为应该使用您的 OpenCV 构建来提供和构建 libtiff。检查您是否拥有它并且它已正确链接。 @Naveh 我不明白为什么没有 -Wl 标志它一切正常,以及为什么它用标志吐出这些错误,rpath 应该只添加一个用于链接目的的搜索目录,而不是破坏现有链接路径 【参考方案1】:

这个话题很老了,但我遇到了同样的问题,我已经解决了。

我尝试重新安装OpenCV,我终于用ccmake发现了

BUILD_TIFF |关闭

是安装 OpenCV 时的默认参数。

所以我把它打开并重新安装 OpenCV,它就可以工作了。

【讨论】:

以上是关于仅在使用 -Wl、-rpath、/usr/local/MATLAB/R2014b/bin/glnxa64 添加 Matkab 代码后链接错误 OpenCV的主要内容,如果未能解决你的问题,请参考以下文章

仅在 useEffect 之后使用数据

仅在满足条件时使用提示

SwiftUI:仅在 iOS 14+ 上使用“accessibilityIdentifier”

仅在出现错误时创建 Python 日志文件(使用日志记录模块)

使用 UIPanGestureRecognizer 仅在 UIImageview 框架中拖动 UILabel

为啥 glreadpixels 仅在某些情况下有效?