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:
- When I did a search in Google on this problem, I discovered from an old forum post that the jpeg library compiles in C. This apparently causes the C++ compiler to mess up names. I'm not clear on what this means, but I followed advice to add:
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.
In my makefile, I have checked all of my includes and paths. These do not seem to be the problem. Also, I have similar paths and includes for other libraries in other directories, and they're fine.
I also added: -lstdc++ to my list of compiler options (from advice on another old forum post). It had zero effect.
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:
- First added "-lgems3k -L/usr/lib -ljpeg" to my LIBS (the libraries). This leads to the errors below.
- Then added (leads to same error as original): OPTIONS = -O3 -fpermissive -w -DSAMG_UNIX_LINUX -DSAMG_LCASE_USCORE -DNDEBUG -DCSP_WITH_SAMG_SOLVER -/usr/lib/libjpeg.so.62
-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...
-ljpeg
to your list of libraries that you link against. - Mats Petersson-L/usr/lib64
on the linker line. - Mats Peterssonextern "C" { ... }" around the include in
grid.cpp`? - Mats Petersson