在 linux 中静态链接库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3870121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:35:46  来源:igfitidea点击:

Statically linking libraries in linux

clinuxgcc

提问by Ravi Gupta

I have an application which links to a number of libraries, most of them are available as both static as well as dynamic library on my machine. Below is the output of the lddcommand.

我有一个链接到许多库的应用程序,其中大多数在我的机器上既可用作静态库,也可用作动态库。下面是ldd命令的输出。

linux-gate.so.1 =>  (0xffffe000)
libssl.so.0.9.8 => /usr/lib/libssl.so.0.9.8 (0xb782c000)
libc.so.6 => /lib/libc.so.6 (0xb76cc000)
libcrypto.so.0.9.8 => /usr/lib/libcrypto.so.0.9.8 (0xb755a000)
/lib/ld-linux.so.2 (0xb788d000)
libdl.so.2 => /lib/libdl.so.2 (0xb7555000)
libz.so.1 => /lib/libz.so.1 (0xb7540000)

I want to statically link libssl library but as per the gcc documentation, by default it links every library dynamically. What is the method to tell gcc to link a specific library statically even its dynamic version is also available on the system?

我想静态链接 libssl 库,但根据 gcc 文档,默认情况下它动态链接每个库。即使系统上也可以使用动态版本,告诉 gcc 静态链接特定库的方法是什么?

回答by facha

gcc has a -static flag.

gcc 有一个 -static 标志。