"An introduction to GCC" by Brian Gough
gcc -Wall hello.c -ohello
-Wall turns on all the most commonly-used compiler warnings.
"-c" is used to compile a source file to an object file. When compiling with "-c" the compiler automatically creates an object file whose name is the same as the source file, with '.o'.
To link object files together:
gcc main.o hello_fn.o -o hello (the only place we don't need -Wall)
Traditional behavior of compiler and linkers is to search for external functions from left to right in the object files specified on the command line. It's best to follow this.
In general, linking is faster than compilation.
The compiler option '-lName' will attempt to link libName.so firstly or libName.a if libName.so is not found.
Link order of libraries: A library which calls external function defined in another library should appear before the library containing the function. As for object files, most current compilers will search all libraries, regardless of order.
By default, gcc searches the following directories for header files (include path):
usr/local/include
usr/include
and the following directories for libraries (link path):
usr/local/lib
usr/lib
'-I' add directories to the include path
'-L' add directories to the library search path (or link path)
.a static library
.so shared object
static linking can be forced with the '-static' option to gocc to avoid the use of shared libraries.
Monday, January 21, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment