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.