Friday, January 23, 2009

C Linux - Making Libraries - Static and Dynamic

We will be using two files namely main.c and hello.c as following:

//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`

Run the application to test
#./dynamic_link_exe

To verify that dynamically linked executable files share libraries, you can do
#strings dynamic_link_exe | grep hello

Running Microsoft Internet Explorer on Linux

IE4Linux
Download and Install

wine - Running windows apps on Linux

Wine - running windows apps on Linux