A. B
A. B

Reputation: 717

how to build a c file into a shared object (library) in linux

I need to build a hello world function into a dynamic library. I'm coding in C language on linux. Can anyone help with some sample code doing that? And also for linking against the generated library?

Upvotes: 0

Views: 1005

Answers (2)

user1277476
user1277476

Reputation: 2909

Dig up a copy of libtool and use it. It knows a LOT of the (disturbingly variable) details of how to compile and link a shared library on a large number of operating systems.

http://www.gnu.org/software/libtool/manual/html_node/Using-libtool.html

Upvotes: -2

Aftnix
Aftnix

Reputation: 4589

First compile files to object code

$gcc -Wall -fPIC -c test1.c test2.c 

-fPIC means that it will produce position independent code.

$gcc -shared -o libtest.so test1.o test2.o

Upvotes: 3

Related Questions