为什么包括未定义的引用外部VAR和funcs中结果的.h文件 [英] Why including an h file with external vars and funcs results in undefined references
问题描述
如果我想这些外部在使用dlopen运行时解析是什么?
What if I want these externals to be resolved in runtime with dlopen?
我试着去理解为什么包括.h文件,共享库外部的VAR和funcs中,在未定义/未解决的一个C可执行程序的结果。 (链接时)
Im trying to understand why including an h file, with shared library external vars and funcs, to a C executable program results in undefined/unresolved. (when linking)
为什么我要-lsomelib标志添加到海湾合作委员会的联系,如果我只希望这些符号在运行时得到解决。
Why do I have to add "-lsomelib" flag to the gcc linkage if I only want these symbols to be resolved in runtime.
这是什么的链接时,链接器需要这些deffinitions决议。为什么不能使用dlopen时,等待在运行时的分辨率。
What does the link time linker need these deffinitions resolutions for. Why cant it wait for the resolution in runtime when using dlopen.
谁能帮助我理解?
推荐答案
下面的东西,可以帮助理解:
有3种类型的链接:
Here something that may help understanding: there are 3 types of linking:
- 静态链接(.a)中:编译器包括图书馆的链接时内容到code,这样就可以用相同的架构移动code到其他计算机上并运行它。 LI>
- 动态链接(的.so):编译器在解析链接时符号(编译时);但不包括在可执行文件库的code。当程序开始时,库加载。并且如果库中没有找到程序停止。您需要一个正在运行的程序在计算机上库
- 动态加载:你是负责在运行时加载的库函数,使用dlopen等专门用于插件
另见: http://www.ibm.com/developerworks/库/ L-动态库/ 并
<一href=\"http://stackoverflow.com/questions/9688200/difference-between-shared-objects-so-static-libraries-a-and-dlls-so\">Difference共享对象(的.so),静态库(.a)中,和之间的DLL的(的.so)?
这篇关于为什么包括未定义的引用外部VAR和funcs中结果的.h文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!