![]() |
|
#1
|
|||
|
|||
Linking problem with jpeg and the stdc++ (linux 64bits)Hello,
This is my first post. My name is Giuseppe, I’m a programmer and work in image processing for satellite application. I have a problem to compile a c++ code using jpeg lib on a 64 bits Linux machine (fedora 9 64bits). To explain better the problem, I have the follows two simple program (in c and in c++) CPP / C++ / C Code:
and CPP / C++ / C Code:
If I try to compile, I obtain the follow situation: gcc jpegtest.c -o jpegtest_c -ljpeg OK g++ jpegtest.cpp -o jpegtest_cpp –ljpeg undefined reference to `jpeg_CreateCompress(jpeg_compress_struct*, int, unsigned long)' gcc jpegtest.cpp -o jpegtest_cc -ljpeg -lstdc++ undefined reference to `jpeg_CreateCompress(jpeg_compress_struct*, int, unsigned long)' I reach to compile c code that use jpeg lib but not c++ code! its seams that the stdc++ make some confusion in the linking phase. I have already compiled that code on a 32bits linux machine without problems. Someone can help me? Many thanks! Giuseppe |
|||
|
#2
|
|||
|
|||
Re: Linking problem with jpeg and the stdc++ (linux 64bits)Quote:
What happens when you try Code:
Note that my command line has an ascii '-' in front of the "ljpeg." Yours has something else. (Hex e2 80 93) Maybe your compiler is set up differently than on my installation, and I have no way of testing unicode or whatever other input encoding you (and your Fedora installation) are using. Note also, that my compiler gives a "no such file or directory message rather than the undefined symbol one, so I'm guessing that is not hte problem. Just a guess. However... The command line that I showed works on my Centos 5.2 64-bit workstation (g++ version 4.1.2). I have no way of testing Fedora 64-bit distributions these days, but I have noted in the past that sometimes some distributions (not just Fedora) don't set up library search paths correctly in cases where 32-bit and 64-bit libraries are both installed. So, if there is libjpeg.so in /usr/lib and also in /usr/lib64, the linker might erroneously pick the 32-bit library (in /usr/lib), in which case you could get an "undefined reference" error. Quote:
I'm not sure why you would want to do this, but I'm thinking that if the "g++" command line doesn't work, then "gcc...-lstdc++" won't work either. Quote:
If my command line doesn't work, then try the following: Look for libjpeg files in /usr/lib and /usr/lib64: Code:
If libjpeg.so appears in both directories, then you might try the following: Code:
If this works, then you might even temporarily change the name of "/usr/lib/libjpeg.so" to something else. See Footnote. Try compiling again with Code:
Regards, Dave Footnote: The "correct" thing to do, instead of renaming the library file of an installed 32-bit package is to use yum to uninstall the 32-bit package. I can't imagine that you would need the 32-bit library on a 64-bit installation anyhow. The "rename" trick is just for verification. |
|
#3
|
|||
|
|||
Re: Linking problem with jpeg and the stdc++ (linux 64bits)Hello Dave,
Thanks a lot for the answer! Now in the machine exists only the jpeg lib installed from the source distribution jpeg-6b.tar.gz, libjpeg appears only in the directory /usr/local/lib (checked with ldconfig -v). I have changed the order of the argument in the command line (as you suggest) but the result is the same. It’s very strange problem, I don’t understand why the compilation ends successful when compile c code end fails with c++ code ….. maybe this is a sign to change work?! |
|
#4
|
|||
|
|||
Re: Linking problem with jpeg and the stdc++ (linux 64bits)Quote:
How did you install the library? Did you compile it from scratch or what? I always use yum for such things so that all file locations are known and so that upgrades can happen in a sane way. The fact that you didn't get a messag about not finding the file indicates that it found a libjpeg file somewhere. See Footnote. Try Code:
You might try uninstalling the jpeg stuff that you compiled from scratch and, then: As root: Code:
This works with RedHat-like distributions like Centos, and I assume that it would work with Fedora. Sorry that I can't help beyond this point. Regards, Dave Footnote: In your source installation does /usr/include/jpeglib.h have the following near the beginning: CPP / C++ / C Code:
And the following near the end: CPP / C++ / C Code:
If not, then including this header in a c++ program won't work. You could get the undefined symbol error message. |
|
#5
|
|||
|
|||
Re: Linking problem with jpeg and the stdc++ (linux 64bits)Quote:
I just downloaded and untarred jpegsrc.v6b.tar.gz. Indeed, the cplusplus stuff was not in jpeglib.h. Here's a plan: Copy jpeglib.h to a file with another name (just in case). For example: Code:
Then edit jpeglib.h to insert the lines shown above something like this: Change stuff at the beginning (somewhere around line 13) to: CPP / C++ / C Code:
And near the end: CPP / C++ / C Code:
Execute the following from the jpeg-6b directory: Code:
If all goes well, then, as root: Code:
Regards, Dave Footnote: I still recommend using yum to manage packages like this, but it is possible, I think, to do it from source. |
|
#6
|
|||
|
|||
Re: Linking problem with jpeg and the stdc++ (linux 64bits)Works!!!
I'm very happy, thanks a lot Dave! I'll keep in mind your suggestions about the use of yum to manage packages!! Giuseppe |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The