简体   繁体   English

将Visual Studio中的静态库与复合依赖项链接

[英]Linking static libraries in visual studio with composite dependencies

Suppose you have two static libraries A and B such that A references methods from B. Is it possible to statically link an executable to A and B such that there are not unresolved symbols in B referenced by A? 假设您有两个静态库A和B,使得A引用了B的方法。是否可以将可执行文件静态链接到A和B,以使B中没有被A引用的未解析符号?

Here is my situation: 这是我的情况:

When I try to link everything up that way in Visual Studio 2010, there are unresolved symbols between A and B.. but not between the application and A. The symbols it complains about have the __imp prefix (which do not, and should not, exist in B's DUMPBIN). 当我尝试以这种方式在Visual Studio 2010中链接所有内容时,A和B之间存在未解析的符号。但是应用程序和A之间没有。符号所抱怨的符号带有__imp前缀(该符号不应该也不应该,存在于B的DUMPBIN中。 Why is it looking for symbols with the __imp prefix even though none of the libs are built as DLL's and I have included all of the required "Additional Library Dependencies/Directories" in all of the projects? 即使没有一个库是作为DLL构建的,并且我在所有项目中都包含了所有必需的“其他库依赖项/目录”,为什么还要寻找带有__imp前缀的符号? Also, everything is built with the exact same compiler. 而且,所有内容都使用完全相同的编译器构建。

EDIT: It may be helpful to know that if library B is built as a DLL with an import library instead of a static library, everything will link up correctly. 编辑:知道库B是用导入库而不是静态库作为DLL构建的DLL,可能会有所帮助。

EDIT: I am almost certain it is not a preprocessor condition causing a declspec() or something, because there are no linker errors when the App uses B.. just when A uses B. 编辑:我几乎可以肯定,这不是导致declspec()之类的预处理条件,因为当应用程序使用B时,没有链接器错误。

ANSWER: Both Edwin and JimR are correct, there was actually a macro being used in a header causing a declspec, but I was too stubborn to notice it when they first mentioned that possibility. 解答:Edwin和JimR都是正确的,实际上在标头中使用了一个宏,从而导致了declspec,但是当他们第一次提到这种可能性时,我实在太固执了,没注意到它。 Thanks guys for your patience. 谢谢你们的耐心配合。

the dependecies should not matter ! 依赖关系不重要! they may even be circular ,like A refs B and B refs A. It sounds to me (since you get linker errors) that either you don't have headerfiles for those libs (do you declare funcs from A in B by hand or funcs from B in A) or the headerfiles compile differently in your program and in your libs (due to some #define or compiler option). 它们甚至可能是圆形的,例如A ref B和B refA。对我来说(因为出现链接器错误),您可能没有这些库的头文件(您是手动从B中的A声明func还是funcs)从A中的B开始)或头文件在程序和lib中的编译方式有所不同(由于某些#define或编译器选项)。 Do you use the same calling conventions in both prog and libs ? 在prog和libs中都使用相同的调用约定吗?

I do not have MSVS 2010 to look at, so take this with a grain of salt. 我没有要看的MSVS 2010,因此请带一点盐。

If the symbols have imp in the name, that means either there's a declspec(dllimport) floating around somewhere, a (possibly embedded in the code) compiler switch forcing A to see B as a DLL or you're linking old stuff and not what's currently being produced by the build process. 如果符号名称中有小鬼 ,则意味着某个地方有一个declspec(dllimport)浮动,一个(可能嵌入在代码中的)编译器开关强制A将B视为DLL,或者您正在链接旧内容而不是什么东西当前由构建过程生成。

Was the project you're using imported from an older version of MSVS? 您使用的项目是从旧版本的MSVS导入的吗? I had a similar problem with a poorly managed project that was imported into MSVS 2008 a few years ago... 我几年前导入MSVS 2008的管理不善的项目也遇到类似的问题...

Either way, check A's build environment carefully and make sure you look for pragmas that embed compiler/linker switches. 无论哪种方式,请仔细检查A的构建环境,并确保您寻找嵌入了编译器/链接器开关的编译指示。

由于以前将lib B用作DLL,因此在生成lib A时,您的lib B仍然是DLL,而将lib更改为库时却忘记了重建A。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM