LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 09-02-2003, 02:10 PM   #1
tceast
LQ Newbie
 
Registered: Sep 2003
Posts: 6

Rep: Reputation: 0
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
 
Old 09-02-2003, 11:22 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.
 
Old 09-03-2003, 06:34 AM   #3
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
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.
 
Old 09-03-2003, 09:41 AM   #4
tceast
LQ Newbie
 
Registered: Sep 2003
Posts: 6

Original Poster
Rep: Reputation: 0
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??
 
Old 09-03-2003, 10:23 AM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.
 
Old 09-03-2003, 11:22 AM   #6
tceast
LQ Newbie
 
Registered: Sep 2003
Posts: 6

Original Poster
Rep: Reputation: 0
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?
 
Old 09-03-2003, 11:54 PM   #7
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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?
 
Old 09-04-2003, 04:21 AM   #8
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
Quote:
What library calls the pthread.h header?
how about /usr/lib/libpthread.{a,so} so maybe try -lpthread
 
Old 09-08-2003, 07:15 AM   #9
bwMarkus
LQ Newbie
 
Registered: Aug 2003
Posts: 13

Rep: Reputation: 0
I had a problem which looks quite similar. Do a search on user="bwMarkus", there's also a problem with static linking.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem when trying to static link with gcc glvgfz Programming 11 09-18-2005 07:58 PM
about GCC compiler and static memory grupoapunte Programming 1 05-07-2005 07:11 PM
How can I use gcc to build a static library? vtluu Red Hat 1 04-12-2004 10:45 AM
RH9 static compile doesn't work tceast Red Hat 0 09-03-2003 09:54 AM
Finding and Linking Static Libraries with gcc neorich Programming 15 08-10-2003 04:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration