我的小组正在开发一个程序,该程序使用依赖于JPEG库的JasPer库。我的同事创建了一个Makefile,它在构建规则中列出了-ljpeg
之前的-ljasper
。这在我的同事的计算机上运行良好,但不会在我的计算机上构建:
$ make
cc -DDEBUG compress_image_test.c -o compress_image_test -Wall -ljpeg -ljasper -lm -lcheck
/usr/local/lib/libjasper.a(jpg_dec.o): In function `jpg_decode':
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:158: undefined reference to `jpeg_std_error'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:159: undefined reference to `jpeg_CreateDecompress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:162: undefined reference to `jpeg_stdio_src'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:165: undefined reference to `jpeg_read_header'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:168: undefined reference to `jpeg_start_decompress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:190: undefined reference to `jpeg_read_scanlines'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:197: undefined reference to `jpeg_finish_decompress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:200: undefined reference to `jpeg_destroy_decompress'
/usr/local/lib/libjasper.a(jpg_enc.o): In function `jpg_encode':
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:284: undefined reference to `jpeg_std_error'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:285: undefined reference to `jpeg_CreateCompress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:288: undefined reference to `jpeg_stdio_dest'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:294: undefined reference to `jpeg_set_defaults'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:310: undefined reference to `jpeg_set_quality'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:314: undefined reference to `jpeg_default_colorspace'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:317: undefined reference to `jpeg_start_compress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:324: undefined reference to `jpeg_write_scanlines'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:329: undefined reference to `jpeg_finish_compress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:330: undefined reference to `jpeg_destroy_compress'
collect2: ld returned 1 exit status
make: *** [compress_image_test] Error 1
两台机器都在运行Ubuntu 12.04。 JasPer和JPEG库是从源代码构建的,不是通过apt-get
获得的。
在阅读了另一个堆栈交换帖子lib dependencies and their order后,我尝试更新makefile以将-ljpeg
的订单交换到-ljasper
之后。这很有用。
所以我的问题是,在另一台机器上的原始订单是否正常,这基本上等同于我的,但它在我的机器上不起作用?
5月5日更新:
这些是我可以在计算机上找到的相关库文件:
/ usr / lib中/ I386-Linux的GNU:
lrwxrwxrwx 1 root root 18 Jun 21 2012 libjasper.so.1 -> libjasper.so.1.0.0
-rw-r--r-- 1 root root 317148 Jan 11 2012 libjasper.so.1.0.0
lrwxrwxrwx 1 root root 16 Nov 22 07:42 libjpeg.so.8 -> libjpeg.so.8.0.2
-rw-r--r-- 1 root root 284436 Nov 22 07:42 libjpeg.so.8.0.2
的/ usr /本地/ lib中:
-rw-r--r-- 1 root root 1361856 May 2 09:14 libjasper.a
-rwxr-xr-x 1 root root 757 May 2 09:14 libjasper.la
-rw-r--r-- 1 root root 1461672 May 2 09:15 libjpeg.a
-rwxr-xr-x 1 root root 918 May 2 09:15 libjpeg.la
lrwxrwxrwx 1 root root 16 May 2 09:15 libjpeg.so -> libjpeg.so.9.1.0
lrwxrwxrwx 1 root root 16 May 2 09:15 libjpeg.so.9 -> libjpeg.so.9.1.0
-rwxr-xr-x 1 root root 955739 May 2 09:15 libjpeg.so.9.1.0
和我的同事计算机上存在的文件相同:
/ usr / lib中/ I386-Linux的GNU:
lrwxrwxrwx 1 root root 18 Oct 29 2013 libjasper.so.1 -> libjasper.so.1.0.0
-rw-r--r-- 1 root root 317148 Jan 11 2012 libjasper.so.1.0.0
lrwxrwxrwx 1 root root 16 Nov 22 07:42 libjpeg.so.8 -> libjpeg.so.8.0.2
-rw-r--r-- 1 root root 284436 Nov 22 07:42 libjpeg.so.8.0.2
的/ usr /本地/ lib中:
-rw-r--r-- 1 root root 1320124 Apr 24 16:01 libjasper.a
-rwxr-xr-x 1 root root 750 Apr 24 16:01 libjasper.la
-rw-r--r-- 1 root root 1462456 Apr 24 16:06 libjpeg.a
-rwxr-xr-x 1 root root 918 Apr 24 16:06 libjpeg.la
lrwxrwxrwx 1 root root 16 Apr 24 16:06 libjpeg.so -> libjpeg.so.9.1.0
lrwxrwxrwx 1 root root 16 Apr 24 16:06 libjpeg.so.9 -> libjpeg.so.9.1.0
-rwxr-xr-x 1 root root 955351 Apr 24 16:06 libjpeg.so.9.1.0
据我所知,两个系统上都存在所有相同的文件和链接。
答案 0 :(得分:1)
您可能正在链接静态库。
对于动态库,整个库都包含在链接中,这将使所有符号可用于后面提到的对象,而对于静态库,只有那些满足当前未定义的归档成员符号被链接,而库的其余部分被忽略。
答案 1 :(得分:0)
动态库有两种可能性:
如果您将LD_LIBRARY_PATH
设置为包含其中libjpeg.so
可找到的路径,则ld
会在找到libjpeg.so
时自动搜索libjasper.so
libjasper.so
需要它。
可以使用-rpath
ld
选项构建ld
。在这种情况下,libjasper.so
也会自动在该路径中搜索依赖库。
您可以readelf -d /path/to/libjasper.so
找出{{1}}中是否存在rpath。