Author: www.linuxfans.org mozilla1. GCC includes C / C compiler GCC, CC, C , G , GCC and CCs are the same, C and G are the same, (did not see what the half sentence is meaningful :)) General C procedure GCC compiles, C programs use G compilation 2. GCC's basic usage GCC Test.c This will compile a program named a.out. Why do you show Undefined Reference to 'XXXXX' error? First this is a link error, not compiling errors, that is, if there is only this error, you don't have a problem with your program source itself, you use the compiler to compile the parameter is not right, you don't specify the link to use the library, For example, you have used some mathematical functions in your program, then you have to specify the program in the compilation parameter to link the math library, and the method is to join -LM in the compile command line. 4. -l parameter and -l parameter -L parameter is used to specify the library to be linked, the -l parameter is the library name, then what is the relationship between the library name and the true library name? Just take the mathematics library, his library name is M. His library name is libm.so, it is easy to see that the head lib and the tail of the library file name. SO is the library name. Ok, now we know how to get the name. For example, we have to use a third-party library name called libtest.so, then we only need to copy libtest.so to / usr / lib, compile, compile - LTest Parameters, we can use the libtest.so library (of course, we need to use the function of libtest.so ", we also need the header file with libtest.so). The library placed in / lib and / usr / lib and / usr / local / lib and can be linked directly with the -l parameter, but if the library file is not placed in these three directories, it is placed in other directories. At this time, we only use the -l parameter, the link will still be wrong, the error message is probably: "/ usr / bin / ld: cannot find -lxxx", that is, the linker LD can't find libxxx in that three directory. SO, then another parameter -L will send it, such as the common X11 library, put it in / usr / x11r6 / lib directory, we need to use -l / usr / x11r6 / lib -lx11 The parameter, the -l parameter follows the directory name where the library file is located.
For example, we put libtest.so in / aaa / bb / ccc directory, the link parameter is -l / aaa / bbb / ccc -ltest, most libxxxx.so is just a link, with RH9 as an example, such as libm .so it is linked to /lib/libm.so.x ,/lib/libm.so.6 links to /lib/libm-2.3.2.so, if there is no such link, it will be wrong because LD will only Looking for libxxxx.so, so if you want to use the XXXX library, only libxxxx.so.x or libxxxx-xxxso, make a link to LN -S libxxx-xxxxi libxxxx.so handmade write link parameters always Visually, there are many library development packs to provide a program that generates link parameters. The name is generally called XXXX-Config. Generally, in / usr / bin directory, such as gtk1.2's link parameter generating program is gtk-config, execution GTK-Config --Libs can get the following output "-L / usr / lib -l / usr / x11r6 / lib -lgtk -ldk -rdynamic -lmodule -lglib-ldl -lxi -lxext -lx11 -lm", this is Compile a GTK link parameter required for GTK1.2 program, XXX-Config has a parameter in addition to -libs parameters is --cflags used to generate the header file containing the directory, that is, the -i parameter, below we will Tell. You can try GTK-Config --Libs --cflags to see the output results. The problem now is how to use these outputs, the most stupid method is to copy paste or copy, the smart method is to join this `xxxx-config --libs --cflags`, such as compiling a GTK program: GCC gtktest.c `gtk-config --libs --cflags is almost. Pay attention to `Not single quotes, but 1 button on the left. In addition to XXX-Config, now new development packs generally use pkg-config to generate link parameters, use the way to XXX-Config, but XXX-Config is a specific development package, but pkg-config contains many development packages. The generation of the link parameters, with the pkg-config --List-all command can list all the supported developments, the use of pkg-config is pkg-config pagname --libs --cflags, where PAGNAME is the name, which is PKG. -config - List of lists in List, such as GTK1.2's name is GTK , PKG-Config GTK --LIBS - CFLAGS's role is the same as gtk-config --libs --cflags. For example: GCC gtktest.c `pkg-config gtk --libs --cflags`. 5. -include and -i parameter -include is used to include header files, but in general, the header file is included in the source code with #include xxxxxx, and the -Include parameter is rare.