Help With libjpeg

Apprentice
Posts: 10
Joined: 2006.10
Post: #1
I need to use libjpeg for a project. I followed the install instructions I found online

Code:
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
./configure --enable-shared --enable-static
make
sudo make install
sudo ranlib /usr/local/lib/libjpeg.a
And ended up with this...

Code:
zippy:/usr/local/lib luke$ ls
libjpeg.a       libjpeg.la
Now I need to link the files lib when I compile my project...

How do I do this?

I would have thought (the project is an opengl model viewer)
Code:
zippy:~/Desktop/project spinner$ g++ -o Viewer 3dsLoader.o ImageLoader.o Viewer.o -Wall -framework OpenGL -framework GLUT -L/usr/local/lib
but it doesn't work and I get

Code:
/usr/bin/ld: Undefined symbols:
jpeg_std_error(jpeg_error_mgr*)
jpeg_read_header(jpeg_decompress_struct*, int)
jpeg_read_scanlines(jpeg_decompress_struct*, unsigned char**, unsigned int)
jpeg_CreateDecompress(jpeg_decompress_struct*, int, unsigned long)
jpeg_start_decompress(jpeg_decompress_struct*)
jpeg_finish_decompress(jpeg_decompress_struct*)
jpeg_resync_to_restart(jpeg_decompress_struct*, int)
jpeg_destroy_decompress(jpeg_decompress_struct*)
collect2: ld returned 1 exit status

I have also tried

Code:
zippy:~/Desktop/project spinner$ g++ -o Viewer 3dsLoader.o ImageLoader.o Viewer.o -Wall -framework OpenGL -framework GLUT -ljpeg
/usr/bin/ld: Undefined symbols:
jpeg_std_error(jpeg_error_mgr*)
jpeg_read_header(jpeg_decompress_struct*, int)
jpeg_read_scanlines(jpeg_decompress_struct*, unsigned char**, unsigned int)
jpeg_CreateDecompress(jpeg_decompress_struct*, int, unsigned long)
jpeg_start_decompress(jpeg_decompress_struct*)
jpeg_finish_decompress(jpeg_decompress_struct*)
jpeg_resync_to_restart(jpeg_decompress_struct*, int)
jpeg_destroy_decompress(jpeg_decompress_struct*)
collect2: ld returned 1 exit status
Does this mean I haven't installed it correctly?

I actually had to create the /usr/local/lib directory, when I first tried to build the lib I got

Code:
/usr/bin/install -c libjpeg.la /usr/local/lib/libjpeg.la
install: /usr/local/lib/libjpeg.la: No such file or directory
make: *** [install-lib] Error 71
zippy:~/Desktop/jpeg/jpeg-6b spinner$ sudo mkdir /usr/local/lib


Sorry for the noob question.

Thanks

Spinner
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2006.10
Post: #2
Thanks to NCarter and ThemsAllTook on the iDG IRC channel, I now have an answer!

I thought I should post it incase anyone else has the same issue in the future.

My #include statement needed to specify it was a C lib, rather than C++

The correct way to do this is apparently
Code:
extern "C" {
#include <jpeglib.h>
}

Hope that helps someone.

Thanks to IRC channel for the prompt and friendly advice!
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #3
You picked a good forum to ask this question: the MAF isn't exactly full of developers. Rasp

As I said there: most headers take into account C++ by having extern "C" between #ifdef __cplusplus ... #endif macros. Though you shouldn't have to worry about this very often with third party resources, it's a good thing to remember if you ever write anything in C which you then use in C++.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Statically linking to libjpeg? bronxbomber92 5 3,151 Mar 3, 2007 02:31 PM
Last Post: bronxbomber92