Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc linker finding both .so and .a in the library path which is chosen?

Tags:

gcc

linker

If I run

gcc a.c -L /usr/lib -lexpat 

and both libexpat.a and libexpat.so are in /usr lib which one is used by the linker?

like image 360
ojblass Avatar asked Feb 01 '26 04:02

ojblass


1 Answers

By default the shared library (.so) will be chosen.

If you want to change this behavior, -static gcc option may be used

-static

On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.

like image 199
Dmitry Yudakov Avatar answered Feb 03 '26 20:02

Dmitry Yudakov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!