vrb*_*lgi 2 c c++ dynamic static-libraries dlopen
我读过有关静态和动态库的内容.我的问题很少
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.
Run Code Online (Sandbox Code Playgroud)
这是动态链接库的行为.
我的问题是,如果我链接库libUtlities
ld -o EXE main.o -lUtilities
Run Code Online (Sandbox Code Playgroud)
当我运行EXE时,在我第一次使用这些功能之前,libUtlities将被加载到内存中
which i observed in dbx (Solaris debugger)
But will not contribute to the size of the EXE.
Run Code Online (Sandbox Code Playgroud)
1.它是静态链接还是动态链接.?
不幸的是,将"静态"和"动态"的方式过于滥用,特别是在C和C++.所以,我更喜欢以下术语:
链接时链接,又名"静态链接":所有符号在链接时从静态库中解析.结果是一个单片,静态链接的可执行文件,没有加载时依赖性.
负载时链接:这是对现代广告平台的标准做法,未解决的符号查找在共享库(UNIX)或不幸命名的动态链接库在Windows上,只引用(DLL)中被记录在链接时,实际分辨率符号和代码加载发生在加载时.
这导致"动态链接"可执行文件,必须使用加载程序加载(例如ld.so在Linux上).加载是操作系统的一部分,通常对用户是透明的,但它可以检查(例如ldd在Linux上).所有共享库必须在加载时可用,否则程序将无法启动.
运行时链接,又名"动态链接":没有未解析的符号; 相反,运行时动态决定使用dlopen()或在共享/动态库中查找符号LoadLibrary().找不到符号是一个可处理的运行时条件,不是错误.这种技术通常用于插件架构,在Windows上用于代码注入.
但请注意,Linux的共享对象和Windows的DLL之间存在根本的技术差异,它们不仅仅是具有不同名称的相同内容.但是,它们都可以用于加载时和链接运行时.