Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-02-2003, 02:10 PM
|
#1
|
LQ Newbie
Registered: Sep 2003
Posts: 6
Rep:
|
gcc -static doesn't work !
I am trying to compile a C program on Red Hat 9.0 and it works great until I add the -static option to this compile script :
gcc program.c -oprogram -lXm -lXmu -lXt -lX11 -lm \
-L/usr/X11R6/LessTif/Motif1.2/lib \
-L/usr/X11R6/lib -I/usr/X11R6/LessTif/Motif1.2/include
It lists a bunch of 'undefined references' all of which seem to be in
/usr/include/pthread.h & /usr/include/X11/SM/SMlib.h
I know these headers are getting in, because I can add the -E switch and look at the results of the perprocessor output. And the definitions are there!!
What is going on ?? I have lost two days over this, so any help would be apprectiated.
Thanks
Craig
|
|
|
09-02-2003, 11:22 PM
|
#2
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
Since nobody else has replied, I'll take a shot at it... Do you have the right version of each library installed? If I'm not mistaken, libraries ending in ".so" are shared object libraries. Libraries ending in ".a" are the static equivalents. I think you can only statically link using the appropriate ".a" version of the library.
I may be way off base, but I guess it's a place to start. I'm sure someone else will correct me if I'm mistaken though.
|
|
|
09-03-2003, 06:34 AM
|
#3
|
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263
Rep:
|
do you mean undefined reference or unresolved external, theres a big difference. an undefined reference is caused by something wrong with the code, an unresolved external is when a symbol cant be found in the supplied libraries, as the error happends when you compile with the -static flag i'll take a guess at an unresolved external. this means you are missing the static archive version of the library or as Dark_Helmet says "the .a version" so depending on your distribution you want the static devel .rpm/.deb/.epkg/.tar.gz, if your distribution is mandrake then i wish you luck, else they shouldnt be too hard to find.
|
|
|
09-03-2003, 09:41 AM
|
#4
|
LQ Newbie
Registered: Sep 2003
Posts: 6
Original Poster
Rep:
|
Quote:
Originally posted by kev82
do you mean undefined reference or unresolved external, theres a big difference. an undefined reference is caused by something wrong with the code, an unresolved external is when a symbol cant be found in the supplied libraries, as the error happends when you compile with the -static flag i'll take a guess at an unresolved external. this means you are missing the static archive version of the library or as Dark_Helmet says "the .a version" so depending on your distribution you want the static devel .rpm/.deb/.epkg/.tar.gz, if your distribution is mandrake then i wish you luck, else they shouldnt be too hard to find.
|
No, these are 'undefined reference to 'SmcCloseConnection' (as an example) . 'SMlib.h' contains the declaration for most all of the error messages I am getting, and it is included in the output code of the preprosessor. I am stumped !! Any other ideas??
|
|
|
09-03-2003, 10:23 AM
|
#5
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
Hmmmm... did you compile the libraries yourself, or did you install them as binaries from rpm's or the like? If from source, were there any compilation options that might influence the way the libraries are built? I would figure both libraries would suffer the same problem if that were the case... Was the code snagged as a stable release or CVS?
Is there any chance that maybe the include headers and the compiled library don't match up? I mean something like the library is version 1.2, and the headers are version 1.1?
Another grasp at straws: what is the name of the library you're trying to include? I'm going to assume it's 'SMlib' since that's the name of the header you mentioned. Doesn't the command line need "-lSMlib" in that case? The only reason I mention it is that the error sounds very similar to if you were to use the sqrt() function, but forget to add the "-lm" option to gcc.
|
|
|
09-03-2003, 11:22 AM
|
#6
|
LQ Newbie
Registered: Sep 2003
Posts: 6
Original Poster
Rep:
|
Quote:
Originally posted by Dark_Helmet
Hmmmm... did you compile the libraries yourself, or did you install them as binaries from rpm's or the like? If from source, were there any compilation options that might influence the way the libraries are built? I would figure both libraries would suffer the same problem if that were the case... Was the code snagged as a stable release or CVS?
Is there any chance that maybe the include headers and the compiled library don't match up? I mean something like the library is version 1.2, and the headers are version 1.1?
Another grasp at straws: what is the name of the library you're trying to include? I'm going to assume it's 'SMlib' since that's the name of the header you mentioned. Doesn't the command line need "-lSMlib" in that case? The only reason I mention it is that the error sounds very similar to if you were to use the sqrt() function, but forget to add the "-lm" option to gcc.
|
I installed the libraries as RPM's thru the standard install process of redhat 9.0. The error message is coming from functions in the libXt.a and libX11.a libraries with reference to definitions that should be in the SMlib.h and pthread.h header files. I know these header files are being included because I can see them. There is no SMlib, but I did add -lSM and the errors changed to ICE related. I just added -lICE and now the only errors are 'pthread' related. So, I think you have me on the right track. THANK-YOU!!! What library calls the pthread.h header?
|
|
|
09-03-2003, 11:54 PM
|
#7
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
I don't know for certain. I thought all the pthread code was a part of glibc, and I'm reasonably certain glibc is automatically included whenever you compile anything.
Are you getting the same types of unresolved errors, or are they different?
|
|
|
09-04-2003, 04:21 AM
|
#8
|
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263
Rep:
|
Quote:
What library calls the pthread.h header?
|
how about /usr/lib/libpthread.{a,so} so maybe try -lpthread
|
|
|
09-08-2003, 07:15 AM
|
#9
|
LQ Newbie
Registered: Aug 2003
Posts: 13
Rep:
|
I had a problem which looks quite similar. Do a search on user="bwMarkus", there's also a problem with static linking.
|
|
|
All times are GMT -5. The time now is 09:34 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|