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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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-
lrwxrwxrwx 1 root root     22 2009-04-30 00:24 ./libopenjpeg.so.2 -> libopenjpeg-
-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
up vote 2 down vote accepted

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



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

Following link solved the issue for me. How do you link to a specific version of a shared library in GCC

Excerpt from the link that helped me-

Instead of using "-lcurl" use "-l:libcurl.so.3" And ofcourse also use "-L _installed_path_"

My error was the reverse- "Wrong JPEG library version: library is 80, caller expects 62"

To find out which jpeg library my binary was linked against, I did-

ldd my_binary | grep jpeg

output was-

libjpeg.so.8 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libjpeg.so.8

Clearly, the binary was depending on libjpeg8 (library 80), which was why I was getting the error.

To find out if I really had libjpeg62 in my system, I did

ldconfig -p | grep jpeg

output was-

libplayerjpeg.so.3.0 (libc6,x86-64) => /usr/lib/libplayerjpeg.so.3.0
libopenjpeg.so.2 (libc6,x86-64) => /usr/lib/libopenjpeg.so.2
libjpeg.so.62 (libc6,x86-64) => /usr/local/lib/libjpeg.so.62
libjpeg.so.62 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libjpeg.so.62
libjpeg.so.8 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libjpeg.so.8
libjpeg.so.8 (libc6) => /usr/lib/i386-linux-gnu/libjpeg.so.8
libjpeg.so (libc6,x86-64) => /usr/local/lib/libjpeg.so
libjpeg.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libjpeg.so

So in my case, instead of just using -ljpeg, I used this (in the make file)-

-L/usr/lib/x86_64-linux-gnu/ -l:libjpeg.so.62

Don't forget to replace #include (jpeglib.h> in your cpp file with

extern "C" {
#include "jpeglib.h" }

Hope it helps!

share|improve this answer

Your Answer


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.