为什么显式参数用于静态和动态链接

编程入门 行业动态 更新时间:2024-10-09 11:26:49
本文介绍了为什么显式参数用于静态和动态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我主要在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

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.

更多推荐

为什么显式参数用于静态和动态链接

本文发布于:2023-11-23 13:16:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621578.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   参数   链接   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!