静态和动态库链接 [英] Static and dynamic library linking

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

问题描述

在C ++中,静态库A链接到动态库B和C.如果在B中定义的A中使用了Foo类,那么如果不使用Foo,C会链接吗?

In C++, static library A is linked into dynamic libraries B and C. If a class, Foo, is used in A which is defined in B, will C link if it doesn't use Foo?

我以为答案是肯定的,但是我现在遇到了xlc_r7的问题,其中库C表示Foo是未定义的符号,就C而言.我的问题是库C没有使用引用它的类.该链接在Win32(VC6)和OpenVMS中.

I thought the answer was yes, but I am now running into a problem with xlc_r7 where library C says Foo is an undefined symbol, which it is as far as C is concerned. My problem with that is Library C isn't using the class referencing it. This links in Win32 (VC6) and OpenVMS.

这是链接器差异还是PBCAK?

Is this a linker discrepancy or a PBCAK?

新信息:

  1. B取决于C,但反之则不.

  1. B depends on C, but not visa-versa.

我在Windows上没有使用/OPT:REF进行链接,因此它没有问题.

I'm not using /OPT:REF to link on Windows and it links without issue.

推荐答案

静态链接时,两个模块成为一个.因此,当您编译C并将A链接到其中时,就好像您已将A的所有源代码都复制到C的源代码中,然后编译了组合的源代码一样.因此C.dll包含A,它通过Foo对B具有依赖性.您需要将C链接到B的链接库,以满足这种依赖性.

When you statically link, two modules become one. So when you compile C and link A into it, its as if you had copied all the source code of A into the source code of C, then compiled the combined source. So C.dll includes A, which has a dependency on B via Foo. You'll need to link C to B's link library in order to satisfy that dependency.

请注意,根据您的信息,这将在B和C之间建立循环依赖关系.

Note that according to your info, this will create a circular dependency between B and C.

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

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