//Filename : hello.c
#include
void hello()
{
printf("\n in hello.c hello .... \n");
}
//Filename : main.c
#include
int main()
{
printf("\n in main.c calling hello \n");
hello();
}
1) Static Library
#gcc -c -fPIC hello.c -o hello.o
#ar rcs libhello.a hello.o
#gcc -static main.c -L. -lhello -o static_link_exe
#export LD_LIBRARY_PATH=`pwd`
Run the application to test
#./static_link_exe
To verify that statically linked executable files statically linked libraries, you can do
#strings static_link_exe | grep hello
2) Dynamic Library / Shared Library
#gcc -c -fPIC hello.c -o hello.o
#gcc -shared -o libhello.so hello.o
#gcc main.c -o dynamic_link_exe -L. -lhello
#export LD_LIBRARY_PATH=`pwd`
#./dynamic_link_exe
#strings dynamic_link_exe | grep hello

1 comment:
Thank you very much.
instead of
#gcc -c -fPIC hello.c -o hello.o
use
#gcc -c -fPIC hello.c
then only it will work
Post a Comment