LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 02-23-2005, 09:27 PM   #1
alanwolfen
LQ Newbie
 
Registered: Oct 2004
Distribution: Redhat Linux 9
Posts: 11

Rep: Reputation: 0
Compilation flags and linker warnings


gcc -g -c -lpthread -lm test.c test1.c
gcc -g -c test3.c `pkg-config --cflags --libs gtk+-2.0`
gcc -o output -g -lpthread -lm test1.o test2.o test3.o `pkg-config --cflags --libs gtk+-2.0`

I am getting for the first step:
gcc: -lpthread: linker input file unused because linking not done
gcc: -lm: linker input file unused because linking not done

and getting:
gcc: -lgtk-x11-2.0: linker input file unused because linking not done
gcc: -lgdk-x11-2.0: linker input file unused because linking not done
gcc: -latk-1.0: linker input file unused because linking not done
gcc: -lgdk_pixbuf-2.0: linker input file unused because linking not done
gcc: -lm: linker input file unused because linking not done
gcc: -lpangoxft-1.0: linker input file unused because linking not done
gcc: -lpangox-1.0: linker input file unused because linking not done
gcc: -lpango-1.0: linker input file unused because linking not done
gcc: -lgobject-2.0: linker input file unused because linking not done
gcc: -lgmodule-2.0: linker input file unused because linking not done
gcc: -ldl: linker input file unused because linking not done
gcc: -lglib-2.0: linker input file unused because linking not done

If I remove -lpthread for example in the first step. Then it can't compile. Any way to resolve this?

Thanks
 
Old 02-23-2005, 11:50 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Remove the "-c"

The man page for gcc says:
Quote:
-c Compile or assemble the source files, but do not link. The linking stage simply is not done. ...
 
Old 02-24-2005, 03:51 AM   #3
alanwolfen
LQ Newbie
 
Registered: Oct 2004
Distribution: Redhat Linux 9
Posts: 11

Original Poster
Rep: Reputation: 0
If I compiled without -c, then it gives an error:

/tmp/ccsKpvMq.o(.text+0x11b7): In function `log_msg':
/home/test/project/test1.c:453: undefined reference to `message'

message function is found in test2.c with header test2.h already included in test1.c
 
Old 02-24-2005, 05:57 AM   #4
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 274

Rep: Reputation: 30
Could you post test1.h, test2.h completely, and test1/2.c up to around the first function (that is, only the includes, declarations, etc.)?
 
Old 02-24-2005, 08:11 AM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
You need to list all the .c files on the command line that contain code your program needs.

If test1.c calls a function in test2.c, then including test2.h is not enough. You need to execute this command to compile it:
Code:
gcc -g -lpthread -lm test.c test1.c test2.c
#include'ing the header only informs test1.c that the function exists. The compiler doesn't automatically look at test2.c even though test1.c includes its header file.
 
  


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
Makefile question - multiple compilation flags benobi Programming 7 08-11-2005 01:42 PM
CC flags and the like Garp Linux - Software 2 05-17-2004 03:48 AM
rpmbuild flags vejnovic Linux - Software 0 05-03-2004 07:22 AM
user flags Comarez Linux - Newbie 7 01-25-2004 07:22 AM
TCP-Flags?? X11 Linux - Networking 1 04-09-2002 02:41 AM


All times are GMT -5. The time now is 08:53 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration