- write your library code, say sum.c with header file sum.h, and save them in your library folder, say ~/local/lib for the source, and ~/local/include for the header file.
- compile it using gcc
gcc -I ~/local/include -c sum.c
This will produce a object file sum.o - create a static library named "hash", do
ar rcs libhash.a sum.o
More than one *.o files can be included in single library - you are ready to use it by :
- include the "sum.h"
- compile it using gcc -I ~/local/include -L ~/local/lib -lhash ...
# for header files
export C_INCLUDE_PATH=~/local/include:$C_INCLUDE_PATH
# for linking library
exprot LD_LIBRARY_PATH=~/local/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=~/local/lib:$LIBRARY_PATH - include the "sum.h"
Tuesday, November 23, 2010
create shared C library
How to create and use your own shared C library using gcc? This can be done in 4 steps.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment