简体   繁体   English

默认情况下,gcc是否将程序与静态或动态库链接?

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

I have both static and dynamic versions of the same library installed on my Linux system: 我的Linux系统上安装了相同库的静态和动态版本:

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

Which one of these libraries will use gcc, if I set argument -lsample ? 如果我设置参数-lsample,这些库中的哪一个将使用gcc?

gcc xxx.c -lsample

How can I force gcc to use static or dynamic version of the library 如何强制gcc使用库的静态或动态版本

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

You don't have to do anything, dynamic is the default. 您无需执行任何操作,默认情况下为dynamic。

However, it has to add a couple of things to the binary to help it, at runtime, to properly use the dynamic library. 但是,它必须在二进制文件中添加一些内容,以便在运行时帮助它正确使用动态库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM