The same problem has buged me for about two days!
my solution is use:
gcc your_code.c -ljpeg
instead of:
gcc -ljpeg your_code.c
to compile your code.
here is the explanation:Why does the order in which libraries are linked sometimes cause errors in GCC?
hope this will help.