静态VS动态库 [英] Static Vs Dynamic libraries

查看:142
本文介绍了静态VS动态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了一下静态和动态库。
我的问题是小specifie

I have read about static and dynamic libraries. My question is little specifie

的dlopen dlclose:

Benifit of dlopen is  we can start the EXE with out
loading the necessary libraries at the begining. Only when we
need we will load the libratries and unload it from the memory.

这是动态链接libaries的行为。

This is behaviour of dynamic linking libaries.

我的问题是,如果我链接库libUtlities

ld -o EXE main.o -lUtilities 

当我运行的EXE,libUtlities将被载入到内存条前,
我第一次用有功能

When I run the EXE, libUtlities will be loaded to the memory before I first use there functionalities

which i observed in dbx (Solaris debugger)
But will not contribute to the size of the EXE.

1.So它是一个静态链接或动态链接。 ?

推荐答案

不幸的是,在静态和动态是的办法的太过度使用,尤其是在C和C ++。所以,我preFER以下术语:

Unfortunately, the words "static" and "dynamic" are way too overused, especially in C and C++. So, I prefer the following terminology:


  • 链接时链接,a.k.a静态链接:所有的符号从静态库链接时得到解决。其结果是一个整体,静态链接空载时的依赖可执行文件。

  • Link-time linking, a.k.a "static linking": All symbols are resolved at link time from static libraries. The result is a monolithic, statically linked executable with no load-time dependencies.

加载时链接:这是对现代平台的标准做法,未解决的符号在共享库的(UNIX)抬头或不幸命名的动态链接库(DLL)的Windows上,只引用被记录在链接时,符号和code装载的实际分辨率发生在加载时间。

Load-time linking: This is the standard practice on modern platforms, unresolved symbols are looked up in shared libraries (Unix) or the unfortunately named dynamic link libraries (DLLS) on Windows and only references are recorded at link time, the actual resolution of the symbols and code loading happens at load time.

这导致其必须(在Linux例如 ld.so )装载了的装载机的一个动态链接的可执行文件。装载的是操作系统的一部分,通常对用户透明,但它是开放的检查(例如,用 LDD 在Linux上)。所有的共享库必须可用在装载时,否则程序将不会启动。

This results in a "dynamically linked" executable which must be loaded with a loader (e.g. ld.so on Linux). Loading is part of the OS and usually transparent to the user, though it's open to inspection (e.g. with ldd on Linux). All shared libraries must be available at load time, or the program will not launch.

运行时链接,又名动态链接:有没有未解决的符号;相反,在运行时动态决定使用查找符号共享/动态库的dlopen()调用LoadLibrary() 。未能找到符号是不是一个错误handlable运行状态。这种技术通常用于插件架构,并在Windows上code注射液。

Run-time linking, a.k.a. "dynamic linking": There are no unresolved symbols; rather, the runtime dynamically decides to look up symbols in a shared/dynamic library using dlopen() or LoadLibrary(). Failure to find symbols is a handlable runtime condition that is not an error. This technique is used commonly for plug-in architecture, and on Windows for code injection.

不过请注意,有Linux的的共享对象和Windows的DLL文件之间的根本区别的技术,他们不只是用不同的名称同样的事情。既然而,可以既用于负载时和运行时链接。

Note however that there is a fundamental technical difference between Linux's shared objects and Windows's DLLs, they're not just the same thing with a different name. Both can however be used both for load-time and run-time linking.

这篇关于静态VS动态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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