Visual C++中静态库是否可以引用动态库?

来源:互联网 发布:制作淘宝商品拍照箱 编辑:程序博客网 时间:2024/05/21 07:54

问题:

在一个静态库A中是否可以引用一个动态库B的函数呢?

答案:

YES,但是这样一来有个问题需要注意:今后所有引用了该静态库的动态库C都必须引用动态库B,否则就会报链接错误。

但是也有一种方法可以使得静态库A的用户不需要理会这些问题,答案就是在静态库A的主头文件中加入如下一行:

#pragma comment(lib, "B.lib")


A library is just a collection of objects, which by definition have not been linked yet. The linker is not used to create the library, so it makes sense that there would be no linker options for it.


reference:

http://stackoverflow.com/questions/1242820/can-a-c-static-library-link-to-shared-library

http://stackoverflow.com/questions/6476286/why-doesnt-a-c-static-library-project-have-linker-settings/6476299#6476299


原创粉丝点击