Ant
Ant

Reputation: 867

Linking errors on Linux gcc 4.3.4: "undefined reference" related to "jpeg" library (e.g., undefined reference to `jpeg_std_error(jpeg_error_mgr*)')

I am working with a large C++ code that has been developed over a few years. I have added to the code and have been successfully running it on Mac OX 10.7.5. However, it is very slow and I now want to run it on a cluster (g++ (SUSE Linux) 4.3.4 [gcc-4_3-branch revision 152973]). I am not very experienced as far as C++ and I'm a complete newbie as far as dealing with compilation / linking.

I am unable to get past a linking error related to a "jpeg" library and would be very grateful for any help. I have the library code installed in a directory where my code resides, but my understanding is that it is also available from the compiler.

There is a lot of error output, so I won't post it all. Here is the first part:

/data/place/number/account/program/libraries/libfile_intel.a(Grid.o): In function program::Grid<double>::SaveToJPG(char const*, int, bool, bool) const': Grid.cpp:(.text._ZNK3program20GridIdE9SaveToJPGEPKcibb[program::Grid<double>::SaveToJPG(char const*, int, bool, bool) const]+0x499): undefined reference to jpeg_std_error(jpeg_error_mgr*)' Grid.cpp:(.text._ZNK3program20GridIdE9SaveToJPGEPKcibb[program::Grid::SaveToJPG(char const*, int, bool, bool) const]+0x4b5): undefined reference to `jpeg_CreateCompress(jpeg_compress_struct*, int, unsigned long)'

What I have tried:

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

in all of the files in my jpeg directory that contain "#include "jpeglib.h." I wrote, "jpeglib.h" because, as I mentioned, I have a directory containing the jpeg code. However, I did also try to use the jpeg code provided by default and I got a message saying it is not available on the cluster compiler.

One weird observation I have made is that when I do "make" of the entire code (several libraries within various directories), the jpeg library does not make unless I specifically go into its directory and do "make" there. As I said, the code is way too big to post this to demonstrate that I have no path errors. I am pretty sure I don't, but this behavior seems very odd.

If anyone is still with me after this long post, I would be very grateful for any tips. Thanks.

Edit: In my makefile, here is what i have for compiling/linking:

CC = g++

OPTIONS = -O3 -fpermissive -w -DSAMG_UNIX_LINUX -DSAMG_LCASE_USCORE -DNDEBUG -DCSP_WITH_SAMG_SOLVER

Edit 2: result of Svens's advice

I did:

find /usr /opt -iname libjpeg*so*

And got:

/usr/lib/libjpeg.so.62

/usr/lib/libjpeg.so.62.0.0

/usr/lib64/libjpeg.so.62

/usr/lib64/libjpeg.so.62.0.0

/usr/lib64/libjpeg.so find:

/usr/lib64/mozilla': Permission denied find: /usr/lpp/mmfs/gui/runtime': Permission denied me@login1:/data/place/number/account/program/support_libraries/jpeg> cd ../../libraries/ me@login1:/data/place/number/account/program/libraries> find $HOME -iname libjpeg*so*

If my understanding is correct, the library exists and has been found in the "libraries" directory, which is where I expect. My main makefile that links all the libraries has an include path to the directory where the jpeg library resides. The other libraries in that directory are found. What is the "permission denied" doing?

Edit 3: result of Sven's advice to change the makefile options:

Here's what I changed:

-L/usr/lib -ljpeg /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld:

skipping incompatible /usr/lib/libm.so when searching for -lm

/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld:

skipping incompatible /usr/lib/libm.a when searching for -lm

/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld:

skipping incompatible /usr/lib/libc.so when searching for -lc

/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld:

skipping incompatible /usr/lib/libc.a when searching for -lc

/data/place/number/account/program/libraries/lib1_intel.a(Grid.o): In

function `program::Grid::SaveToJPG(char const*, int, bool, bool) const':

Grid.cpp:(.text._ZNK3program20GridIdE9SaveToJPGEPKcibb[program::Grid::SaveToJPG(char const*, int, bool, bool) const]+0x499): undefined reference to `jpeg_std_error(jpeg_error_mgr*)'

and so on...

Upvotes: 2

Views: 15072

Answers (1)

Sven
Sven

Reputation: 1768

Following up on the comments: are you sure you installed libjpeg? Run

find $HOME -iname libjpeg\*so\*

to find the libjpeg you need to link to. This command will most likely yield several results.

You can simply take the first line of this output and append it to your compilation command, but leave out the "-ljpeg" suggested above.

If it does not give any output at all, you don't have libjpeg installed in your home. So either

  • install libjpeg

  • disable the part of the code that needs it if you don't need it either

  • extend your search,

like

find /usr /opt -iname libjpeg\*so\*

... and try with one of the libjpeg installations on the system.

EDIT (after libjpeg was found on the system):

Try appending

/usr/lib/libjpeg.so.62

to the compile command (the OPTIONS variable in your Makefile). If that doesn't work, try

-L/usr/lib -ljpeg

(Edit by Mats:)

Also make sure EVERY place where #include "jpeglib.h" is covered by extern "C" { ... }. It may make sense to replace these with a c++ wrapper include, which does the addition of extern "C" { ... } in one place, and then just include "wrapped_jpeglib.h" in the relevant places.

(End Edit by Mats)

Upvotes: 7

Related Questions