Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a game I'm writing which recently required libjpeg. I wrote some code using libjpeg on some-other-machine and it worked as expected. I pulled the code to this machine and tried compiling and running it and have been getting the runtime error out of libjpeg:

Wrong JPEG library version: library is 62, caller expects 80

If I use ldd to see what the binary is linked to, I get:

ldd Debug/tc | grep jpeg libjpeg.so.62 => /usr/lib/x86_64-linux-gnu/libjpeg.so.62 (0x00007f50f02f2000)

My compile flags include -ljpeg. The current jpeg related shared objects in my /usr/lib looks like this:

find | grep jpeg | xargs ls -l --color
-rwxr-xr-x 1 root root  61256 2011-09-26 15:43 ./gimp/2.0/plug-ins/file-jpeg
-rw-r--r-- 1 root root   5912 2011-10-01 06:40 ./grub/i386-pc/jpeg.mod
-rw-r--r-- 1 root root  40264 2011-08-24 05:41 ./gstreamer-0.10/libgstjpegformat.so
-rw-r--r-- 1 root root  78064 2011-08-24 05:41 ./gstreamer-0.10/libgstjpeg.so
-rw-r--r-- 1 root root  17920 2011-09-27 17:30 ./i386-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-jpeg.so
lrwxrwxrwx 1 root root     17 2011-08-10 14:07 ./i386-linux-gnu/libjpeg.so.62 -> libjpeg.so.62.0.0
-rw-r--r-- 1 root root 145068 2011-08-10 14:07 ./i386-linux-gnu/libjpeg.so.62.0.0
-rw-r--r-- 1 root root  30440 2011-09-30 05:25 ./i386-linux-gnu/qt4/plugins/imageformats/libqjpeg.so
-rw-r--r-- 1 root root    924 2011-06-15 05:05 ./ImageMagick-6.6.0/modules-Q16/coders/jpeg.la
-rw-r--r-- 1 root root  39504 2011-06-15 05:05 ./ImageMagick-6.6.0/modules-Q16/coders/jpeg.so
-rw-r--r-- 1 root root  10312 2011-06-03 00:18 ./imlib2/loaders/jpeg.so
-rw-r--r-- 1 root root  43072 2011-10-21 19:11 ./jvm/java-6-openjdk/jre/lib/amd64/libjpeg.so
-rw-r--r-- 1 root root  23184 2011-10-14 02:46 ./kde4/jpegthumbnail.so
-rw-r--r-- 1 root root 132632 2009-04-30 00:24 ./libopenjpeg-2.1.3.0.so
lrwxrwxrwx 1 root root     22 2009-04-30 00:24 ./libopenjpeg.so.2 -> libopenjpeg-2.1.3.0.so
-rw-r--r-- 1 root root  23224 2011-08-03 04:20 ./libquicktime2/lqt_mjpeg.so
-rw-r--r-- 1 root root  27208 2011-08-03 04:20 ./libquicktime2/lqt_rtjpeg.so
-rw-r--r-- 1 root root  47800 2011-09-24 10:12 ./strigi/strigiea_jpeg.so
-rw-r--r-- 1 root root   3091 2011-05-18 05:25 ./syslinux/com32/include/tinyjpeg.h
-rw-r--r-- 1 root root  22912 2011-09-27 17:38 ./x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-jpeg.so
-rw-r--r-- 1 root root 226798 2011-08-10 14:06 ./x86_64-linux-gnu/libjpeg.a
-rw-r--r-- 1 root root    935 2011-08-10 14:06 ./x86_64-linux-gnu/libjpeg.la
lrwxrwxrwx 1 root root     17 2011-08-10 14:06 ./x86_64-linux-gnu/libjpeg.so -> libjpeg.so.62.0.0
lrwxrwxrwx 1 root root     17 2011-10-15 10:50 ./x86_64-linux-gnu/libjpeg.so.62 -> libjpeg.so.62.0.0
-rw-r--r-- 1 root root 150144 2011-08-10 14:06 ./x86_64-linux-gnu/libjpeg.so.62.0.0
lrwxrwxrwx 1 root root     16 2011-10-15 10:50 ./x86_64-linux-gnu/libjpeg.so.8 -> libjpeg.so.8.3.0
lrwxrwxrwx 1 root root     19 2011-11-30 01:25 ./x86_64-linux-gnu/libjpeg.so.8.3.0.bak -> ./libjpeg.so.62.0.0
-rw-r--r-- 1 root root  31488 2011-09-30 05:13 ./x86_64-linux-gnu/qt4/plugins/imageformats/libqjpeg.so

The original machine runs Gentoo, 'this' machine runs Ubuntu 11.10. Both are 64-bit. The gentoo box only has libjpeg version 8, it seems.

Ultimately, my question is: How can I resolve this? I'd also like to know how I can determine exactly which library the linker has used.

EDIT: My game also links to SDL_image, which according to ldd, links to libjpeg version 8. I bet this is where my troubles stem from. How can I tell gcc to link my game to libjpeg version 8? I tried -l/usr/lib/libjpeg.so.whatever and it complained about not finding the specified lib.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Please use LD_LIBRARY_PATH. Refer to these useful links as well:

http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

http://linuxmafia.com/faq/Admin/ld-lib-path.html

share|improve this answer
    
Thanks, these are good reads. See my edit above -- I think I've narrowed down the issue. I don't think setting LD_LIBRARY_PATH is necessary, and your second link provides some compelling reasons not to do so anyway. –  stephelton Nov 30 '11 at 10:03
    
Intendedly chose to add the second link, emphasising on when not to use the variable. Seems you've figured. –  Nikhil Mulley Nov 30 '11 at 10:06
    
btw, if you are sure of the library path of libjpeg, would not mind trying with -Wl,-rpath,$(LIB_PATH) option of gcc and see how it goes. –  Nikhil Mulley Nov 30 '11 at 10:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.