libpng16.so.16:对inflateReset2@ZLIB_1.2.3.4&#39的未定义引用;

时间:2017-01-03 09:46:18

标签: gcc linker undefined-symbol

我正在我的大学集群上建立一个caffe(3D-caffe),它在/software/software/<package>/<version-compiler>/

中有不同版本的不同软件版本。

当cmake执行此编译步骤时:

g++ -fPIC -Wall -Wno-sign-compare -Wno-uninitialized -O3 -DNDEBUG \
CMakeFiles/caffe.bin.dir/caffe.cpp.o  -o caffe -rdynamic ../lib/libcaffe.so \
../lib/libproto.a /software/software/Boost/1.61.0-foss-2016a/lib/libboost_system.so \
/software/software/Boost/1.61.0-foss-2016a/lib/libboost_thread.so \
-lpthread -lglog /software/software/gflags/2.1.2-foss-2016a/lib/libgflags.so \
-lprotobuf -lpthread -lglog \
/software/software/gflags/2.1.2-foss-2016a/lib/libgflags.so \
-lprotobuf -lhdf5_hl -lhdf5 -lrt -lsz -lz -ldl -lm -lpthread -llmdb -lleveldb -lsnappy \
-lcudart -lcurand -lcublas -lcudnn \
/software/software/OpenCV/3.1.0-foss-2016a/lib/libopencv_highgui.so.3.1.0 \
/software/software/OpenCV/3.1.0-foss-2016a/lib/libopencv_imgcodecs.so.3.1.0 \
/software/software/OpenCV/3.1.0-foss-2016a/lib/libopencv_imgproc.so.3.1.0 \
/software/software/OpenCV/3.1.0-foss-2016a/lib/libopencv_core.so.3.1.0 \
-lopenblas -Wl,-rpath,/home/p253591/3D-Caffe/build/lib:/software/software/Boost/1.61.0-foss-2016a/lib:/software/software/gflags/2.1.2-foss-2016a/lib

TL; DR:要点表单是(注意-lz用于链接到libz):

g++ ... .../caffe.cpp.o  -o caffe .../libcaffe.so .../libproto.a .../libboost_system.so ...more .so's and -lxyz's... -lz

错误:

/software/software/libpng/1.6.23-foss-2016a/lib/libpng16.so.16: undefined reference to `inflateReset2@ZLIB_1.2.3.4'
collect2: error: ld returned 1 exit status

这似乎是正确的,因为当我为-print-file-name=libz.so.1指定g++选项时,会打印/lib/../lib64/libz.so.1,这对于版本来说有点过于陈旧。

我在/software/software/zlib/1.2.8-foss-2016a/lib/中有一个较新的版本,但在我:

  • 将此路径添加到LD_LIBARY_PATH
  • 将其附加到-rpath选项或
  • 使用-L选项
  • 添加它

g++在使用/lib/../lib64/libz.so.1

报告时继续使用-print-file-name

工作原理是删除-lz选项并将/software/software/zlib/1.2.8-foss-2016a/lib/libz.so.1显式添加为要在编译/链接期间包含的文件。但这似乎是一种黑客攻击。

在完成g++选项时,如何让/software/software/zlib/1.2.8-foss-2016a/lib/libz.so.1使用/lib/../lib64/libz.so.1代替-lz?最好间接通过cmake(当建造咖啡时)。

提前谢谢!

修改

ldd说明使用的权利.so

# ldd /software/software/libpng/1.6.23-foss-2016a/lib/libpng16.so.16
        linux-vdso.so.1 =>  (0x00007fff55599000)
        libz.so.1 => /software/software/zlib/1.2.8/lib/libz.so.1 (0x00007f7875b29000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f7875888000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f787566b000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f78752d7000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003328800000)

此外,该符号应该存在于此libz.so.1:

# nm /software/software/zlib/1.2.8/lib/libz.so.1
...
0000000000008270 T inflateReset2
...
0000000000000000 A ZLIB_1.2.3.4
....
#

我在de @中假设undefined symbol - 符号 - 错误某种程度上需要A型符号作为版本检查(但我找不到任何关于此的文档)在ld.so手册页中)

1 个答案:

答案 0 :(得分:1)

我的猜测是,您 -L之后添加-lz ,但-L只会-l影响-rpath 。另请注意,LD_LIBRARY_PATHNaN正在影响运行时库搜索(以及ldd输出),因此它们不会对编译产生太大影响。