Compilation and Header Files |
Linking and Libraries |
Example |
Compile and link:
#include <stdio.h> #include <math.h> main() { int i; float x; for (i = 0; i <= 10; i++) { x = sin(i); printf("i = %d, ", i); printf("x = %f\n", x); } } |
gcc -lm -o maths maths.c |
Search Path Considerations |
Each system will have default search paths on which the compiler and linker will search for header files and precompiled libraries. Sometimes we need to add to the default paths. For example:
gcc -I/home/simonh/my_h -L/home/simonh/my_libs -lmylib my_prog.c |
...previous | up (conts) | next... |