![]() |
||
Navigation News GUI Programming "man of the month" Bookreviews Projects Languages Tutorials/Howtos Tools Crew My hardware Old project page at SF My blog! |
gccgcc - Thats the thing you most likely will be using most of the time, wether you are programming c, c++ or fortran. That's the compiler. But it can not only compile things, it has also contact to ld, the linker, and passes commands on to that. And that is where it gets ugly. If you've read somehing like k&r (over in the books section) they don't talk about the actual compiling, since they want to stay os-independant. So you gotta learn somehow else how to use the wretched thing. But don't try to take a look at the man- and info-pages. They teach you the basic command extentions ok but then drift off hard into strange lands you actually didn't want nothing to know about at this stage (being newbie). So, here are some basic command-extensions:gcc -o foo bar.c produces the executable with name foo after compiling and linking bar.c
g++ -o foo bar.cpp does the same with c++ stuff. gcc is smart enough to figure out what stuff you want to compile given you provide your stuff with the correct ending, like .c .cpp. You can actually learn something from the man-page about the endings, it's described right on top.
So, that's how simple compiling works. But what has to be written when you have mathematical functions in your program? Let's say you use sin() in your code. Then you have to #include <math.h> at the top of your program. OK, that tell gcc to include the stuff written in math.h into your program in order to compile it. But since gcc also talks to ld (but is too stupid to realise that #include <something> means that the linker needs to link with something too) you have to issue this command:
gcc -o foo bar.c -lm
The -lm at the end tells ld (via gcc) to -link mathematic. You can find that deeeeep down in the gcc man-page. What I'm doing with OpenGL at the moment needs this command:
gcc -I. -I. -g -O2 -I/usr/X11R6/include -I/usr/include/SDL -D_REENTRANT -DHAVE_OPENGL -o lesson02a lesson02a.c -L/usr/X11R6/lib -lGL -lGLU -L/usr/lib -lSDL -lpthread -L/usr/X11R6/lib -lXxf86dga -lXxf86vm -lXv
Weird, hmm? I didn't figure this out myself but rather copied it from an example. The -g option is for the use with gdb, the gnu debugger. This inserts some flags and debugging information into the compiled program which gdb uses to figure out whats going on at every step. The -O2 means that gcc may feel free to improve the compiled code. Too much optimization doesn't work together with the -g command - sounds logical, hmm? OK, now something I read yesterday: ld (via gcc) is sensitive about the order in which the libraries are included after the gcc command. If libfoo depends on libbar , then libfoo has to be named first since ld can only keep track of unresolved symbols when it tries to link them. That leads to linker commands like -lfoo -lbar -lfoo if libfoo depends on libbar and libbar in turn also depends on libfoo. OK, so much for now since I want to read a little more about OpenGL now. -Robos News19.11.2001: Well, wrote this page Last update: Tuesday, 05-Nov-2002 01:03:34 CET |
Gnu GCC lf229, SoftwareDevelopment: GCC - the root of all Comments, Errata? Contact robos! Page counter: 2335 |