compile, link, run
gcc -o hello hello.c
instruct compiler to use a library file
gcc -o hello hello.c /usr/lib/limb.a #or# gcc -o hello hello.c -lm
instruct compiler to use a library file (from an external location)
gcc -o hello -L/home/libraries hello.c -lX11
output object files (which can be used to create static library files)
gcc -c one.c two.c # to add functions included in one.c into program.c gcc -c program.c gcc -o program program.o one.o # or create a library first first instead and use that library when compiling ar crv libnumbers.a one.o two.o gcc -o program program.c libnumbers.a
remember to create header files when using functions from libraries
lib.h: void one(char *); void two(int); # ---in the .c file with the main function--- #include "lib.h"
nm command can show which functions are in object, library, program
nm libnumbers.a
ldd command can show all linked libraries a program uses
ldd program