[英]How are symbols resolved when creating a dynamic library?
For example, let's say I have the following structure: 例如,假设我具有以下结构:
my_program | main.c - defines main() | foo.c - defined foo() my_dll | dll_start.c - defined dll_start() | foo.c - defines foo()
where main() calls foo() and then dll_start(). 其中main()调用foo(),然后调用dll_start()。
In what order are they called? 他们叫什么顺序? For example, is it:
例如:
? ?
Basically, I want to know if when you create a dynamic library, if the linker (does the linker even run?) always uses symbols inside the dll when resolving symbols inside the dll itself - for example, in this case, does the foo() inside my_dll call the my_dll::foo or the my_program::foo? 基本上,我想知道是否在创建动态库时,在解析dll自身内部的符号时,链接器(链接器是否还会运行?)是否始终在dll中使用符号-例如,在这种情况下,foo( )在my_dll中调用my_dll :: foo或my_program :: foo?
Yes, the linker runs to finalize the build of the DLL and will need a definition of foo
to build. 是的,链接程序运行以完成DLL的构建,并且需要
foo
的定义才能构建。 But as long as you aren't linking the same library of code containing my_program::foo
into my_dll.dll
, the foo
picked up for linking the DLL itself will be my_dll::foo
. 但只要你不链接含有同一代码库
my_program::foo
进入my_dll.dll
,在foo
拿起了链接DLL本身将my_dll::foo
。
The only time you can get yourself in trouble here is if you had a shared.lib
static code library that implements an independent foo
function and is linked with both with the EXE and DLL. 您唯一遇到麻烦的地方就是拥有一个实现独立
foo
函数并与EXE和DLL链接在一起的shared.lib
静态代码库。 It might be ambiguous which one the DLL picks up if it has a local implementation of foo
. 如果DLL具有本地
foo
实现,则选择哪个DLL可能是模棱两可的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.