简体   繁体   English

在不依赖任何共享库的Linux上构建可执行文件

[英]Build executable on Linux that does not depend on any shared libraries

Environment: Ubuntu 14.04. 环境:Ubuntu 14.04。 gcc 4.8.2 gcc 4.8.2

I am working on a C++ console application. 我正在使用C ++控制台应用程序。 When I run "ldd" on the executable, I see the following: 当我在可执行文件上运行“ ldd”时,看到以下内容:

linux-vdso.so.1 =>  (0x00007fffe495e000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9ffa754000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9ffa38e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9ffa087000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9ffaa6e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9ff9e71000

I am wondering if it is possible to define flags on gcc/linker such that the final executable does not depend on any shared libraries. 我想知道是否有可能在gcc / linker上定义标志,以使最终的可执行文件不依赖于任何共享库。

Simply add -static while linking :-) 只需在链接时添加-static :-)

Static linking should be avoided not only for security reasons. 不仅出于安全原因,还应避免静态链接。

BTW: As I know there is no way to create a static lib from a dynamic one. 顺便说一句:据我所知,无法从动态库创建静态库。 So if you have only the shared lib, you can't link static. 因此,如果只有共享库,则无法链接静态库。

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

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