如何修复 Linker 的损坏路径?

如何修复 Linker 的损坏路径?

我正在尝试从源代码在我的 Ubuntu 16.04 上构建一个 repo,一切顺利,直到它到达链接到 OpenCV 的文件。

我收到以下错误:

/usr/bin/ld: cannot find -lIlmImf
/usr/bin/ld: cannot find -llibjasper
/usr/bin/ld: cannot find -llibtiff
/usr/bin/ld: cannot find -llibpng
/usr/bin/ld: cannot find -llibjpeg
/usr/bin/ld: cannot find -lzlib
collect2: error: ld returned 1 exit status
Makefile:305: recipe for target 'lib/libmxnet.so' failed
make: *** [lib/libmxnet.so] Error 1

所以我尝试检查链接器实际上在做什么。我输入了

ld - llibjpeg --verbose 

并得到

attempt to open //usr/local/lib/x86_64-linux-gnu/liblibjpeg.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/liblibjpeg.a failed
attempt to open //lib/x86_64-linux-gnu/liblibjpeg.so failed
attempt to open //lib/x86_64-linux-gnu/liblibjpeg.a failed
attempt to open //usr/lib/x86_64-linux-gnu/liblibjpeg.so failed
attempt to open //usr/lib/x86_64-linux-gnu/liblibjpeg.a failed
attempt to open //usr/local/lib64/liblibjpeg.so failed
attempt to open //usr/local/lib64/liblibjpeg.a failed
attempt to open //lib64/liblibjpeg.so failed
attempt to open //lib64/liblibjpeg.a failed
attempt to open //usr/lib64/liblibjpeg.so failed
attempt to open //usr/lib64/liblibjpeg.a failed
attempt to open //usr/local/lib/liblibjpeg.so failed
attempt to open //usr/local/lib/liblibjpeg.a failed
attempt to open //lib/liblibjpeg.so failed
attempt to open //lib/liblibjpeg.a failed
attempt to open //usr/lib/liblibjpeg.so failed
attempt to open //usr/lib/liblibjpeg.a failed
attempt to open //usr/x86_64-linux-gnu/lib64/liblibjpeg.so failed
attempt to open //usr/x86_64-linux-gnu/lib64/liblibjpeg.a failed
attempt to open //usr/x86_64-linux-gnu/lib/liblibjpeg.so failed
attempt to open //usr/x86_64-linux-gnu/lib/liblibjpeg.a failed
ld: cannot find -llibjpeg

正如我们所见,链接器没有查找正确的文件!另一方面,如果我输入

ld - ljpeg --verbose 

我看到的是:

attempt to open //usr/local/lib/x86_64-linux-gnu/libjpeg.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libjpeg.a failed
attempt to open //lib/x86_64-linux-gnu/libjpeg.so failed
attempt to open //lib/x86_64-linux-gnu/libjpeg.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libjpeg.so succeeded
-ljpeg (//usr/lib/x86_64-linux-gnu/libjpeg.so)
libc.so.6 needed by //usr/lib/x86_64-linux-gnu/libjpeg.so
found libc.so.6 at //lib/x86_64-linux-gnu/libc.so.6
ld-linux-x86-64.so.2 needed by //lib/x86_64-linux-gnu/libc.so.6
found ld-linux-x86-64.so.2 at //lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
ld: warning: cannot find entry symbol _start; not setting start address

因此 libjpeg 库确实存在,链接器只是在寻找错误的文件。

在 makefile 中我有

ifeq ($(USE_OPENCV), 1)
        CFLAGS += -DMXNET_USE_OPENCV=1 $(shell pkg-config --cflags opencv)
        LDFLAGS += $(filter-out -lopencv_ts, $(shell pkg-config --libs opencv))
        BIN += bin/im2rec

pkg-config --cflags opencv并且shell脚本指示的路径pkg-config --libs opencv是正确的。

如有任何帮助我将不胜感激。

编辑:我make uninstall在 OpenCV 源文件夹中运行。之后,构建成功通过。非常奇怪,似乎 OpenCV 搞乱了符号链接。我之前玩过 opencv.pc 文件,但路径缺失或错误。

答案1

我不明白你哪里出了问题。我已经成功编译了它(即使没有sudo apt-get build-dep libopencv-dev):

wget https://github.com/opencv/opencv/archive/2.4.13.5.zip
unzip 2.4.13.5.zip
cd opencv-2.4.13.5
mkdir build
cd build
cmake ..
make -j16
sudo make install

然后pkg-config --libs opencv显示以下内容:

-L / usr / local / lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lrt -lpthread -lm -ldl

pkg-config --cflags opencv

-I /usr/本地/包括/opencv -I /usr/本地/包括

相关内容