我有些怀疑:
用例:
A static library containing a global variable, static variable, a function
and a class defined
A shared library uses these and hence they are part of the same.
A executable program also uses the same and they are part of the same.
The executable loads the shared library on run time发布于 2014-03-31 14:03:36
在定义全局静态的库中,可以按以下方式定义它:
static int g_i=9;当从其他模块访问g_i时,您应该使用extern告诉编译器,g_i是在另一个模块中定义的:
extern int g_i;这都是标准C,不管操作系统如何,不同的C编译器之间不应该有任何区别。
库不能引用可执行文件中的任何内容,因为这会导致循环引用,而是应该将可执行文件中的共享功能添加到由现有库和可执行文件引用的第三个库中。
在不同的用例中,您更希望动态加载而不是静态链接。静态库使您的可执行文件更大,而动态库可能导致"DLL地狱“。大多数人在想要在不同程序之间共享代码时使用共享库,当他们只在一个程序中使用库时使用静态库。
https://stackoverflow.com/questions/22762701
复制相似问题