Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does gcc link program with static or dynamic library by default?

Tags:

c++

c

linux

gcc

linker

I have both static and dynamic versions of the same library installed on my Linux system:

/usr/lib/libsample.a
/usr/lib/libsample.so

Which one of these libraries will use gcc, if I set argument -lsample ?

gcc xxx.c -lsample

How can I force gcc to use static or dynamic version of the library

like image 333
Sandro Avatar asked Mar 30 '14 21:03

Sandro


1 Answers

http://www.rapidtables.com/code/linux/gcc/gcc-l.htm

You don't have to do anything, dynamic is the default.

However, it has to add a couple of things to the binary to help it, at runtime, to properly use the dynamic library.

like image 137
Taiki Avatar answered Oct 13 '22 10:10

Taiki