=========================================================== [Static Library (How to Create)] pico hello-1.c -> get hello-1.c gcc -c hello-1.c -> get hello-1.o ar -r hello-1.a hello-1.o -> get hello-1.a (static library) =========================================================== [Static Library (How to Use) pico main-1.c -> get main-1.c gcc -c main-1.c -> get main-1.o gcc -o main-1 main-1.o hello-1.a -> get main-1 ./main-1 -> execute main-1 =========================================================== [Dynamic Library (How to Create)] pico hello-2.c -> get hello-2.c gcc -c hello-2.c -> get hello-2.o gcc -shared -o libhello-2.so hello-2.o -> get libhello-2.so (dynamic library) =========================================================== [Dynamic Library (How to Use) pico main-2.c -> get main-2.c gcc -c main-2.c -> get main-2.o gcc -o main-2 main-2.o -L. -lhello-2 -> get main-2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./main-2 -> execute main-2 =========================================================== [Some Notes] 1. gcc -c : compile only, don't link 2. gcc -shared : produce shared object 3. gcc -o filename : put output to the specified file 4. gcc -L path : specify the path to the shared library 5. gcc -l library : specify the name of the shared library 6. ar -r : insert file into the archive 7. export : set environment variables =========================================================== [hello-1.c] #include void hello1(void){ printf("Hello-1 (from static library hello-1.a)"); printf("\n"); } =========================================================== [main-1.c] int main(void){ hello1(); return(0); } =========================================================== [hello-2.c] #include void hello2(void){ printf("Hello-2 (from dynamic library hello-2.so)"); printf("\n"); } =========================================================== [main-2.c] int main(void){ hello2(); return(0); } =========================================================== [Reference] http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20721083.html http://www.linuxman.com.cy/rute/node26.html http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Overall-Options.html#Overall%20Options http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Link-Options.html#Link%20Options ===========================================================