LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Compilation flags and linker warnings (http://www.linuxquestions.org/questions/programming-9/compilation-flags-and-linker-warnings-294122/)

alanwolfen 02-23-2005 09:27 PM

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

Dark_Helmet 02-23-2005 11:50 PM

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. ...

alanwolfen 02-24-2005 03:51 AM

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

Marius2 02-24-2005 05:57 AM

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.)?

Dark_Helmet 02-24-2005 08:11 AM

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.


All times are GMT -5. The time now is 06:41 PM.