为什么显式参数用于静态和动态链接 [英] Why explicit parameters for static and dynamic linking

查看:114
本文介绍了为什么显式参数用于静态和动态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我主要在Windows工作,最近我开始在Linux工作。我有个疑问。我在Windows中使用Visual Studio作为IDE,在Linux中使用Makefile。



Windows中有两种类型的库(VC ++),静态库(.lib)和DLL。很明显(不是吗?)如果我链接lib文件我使用静态链接其他动态链接。



现在当我使用g ++编译器时, 为什么我需要明确提到-Bstatic / -static或-Bdynamic / -dynamic标志。因为如果文件是.a文件,那么我必须使用静态链接,如果文件是.so我使用动态链接。



提前谢谢。

解决方案

你通常不会传递图书馆的全名(完成了它的扩展名),例如当你用 librt 链接时,你不能直接传递 librt.so librt.a ,但在命令行中使用 -lrt 开关(请注意你也这样做在Windows上,对于动态或静态库,链接器的输入文件是 .lib one)。



男人 [ ^ ]对 -BStatic -Bdynamic <提供了很好的解释/ code>

Hi,

I have mostly worked in Windows, and recently I started working in Linux. I have a doubt. I have used Visual Studio as IDE in Windows and used Makefile in Linux.

There are two types of libraries in Windows (VC++), static library (.lib) and DLL. It is quite obvious (isn''t it?) if I link with lib file I am using static linking else dynamic linking.

Now when I use g++ compiler, why I need to explicitly mention -Bstatic/-static or -Bdynamic/-dynamic flags. Because if file is .a file then I must be using static linking and if file is .so I am using dynamic linking.

Thanks in advance.

解决方案

You usually don''t pass the whole name of the library (that is complete with its extension), for instance when you link with librt you don''t pass directly librt.so or librt.a, but use instead the -lrt switch on command line (please note you do the same thing on Windows, for both dynamic or static libraries the input file to the linker is a .lib one).

man[^] provides a good explanation of both -BStatic and -Bdynamic.


这篇关于为什么显式参数用于静态和动态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆