A friend of my asked me how shared libraries are created and used in Linux environment. I really didn’t know this as I have never written C programs, I had to do some googling. I’m writing this page as a reminder for myself and anyone who wants (possibly) bad advises.

1. Compile your library code as objects:

gcc -c libraryfile1.c -fPIC
gcc -c libraryfile2.c -fPIC

2. Link objects into a shared library

gcc -shared -o libmylib.so libraryfile1.o libraryfile2.o

3. Compile actual programs as follows

gcc -o actualprogram -L. -lmylib actualprogram.c

where gcc outputs compilation of actualprogram.c into file actualprogram and links libmylib.so in current directory into it.

(Those who don’t believe these instructions can read them in their original location at vergil.chemisty.gatech.edu)

Apparently shared libraries/dynamic linking libraries work completely different in MSHole in wall” environment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: