Linking Windows DLL files from static libraries using CMake without hand-crafting unresolved symbol names

后端 未结 1 1088
遇见更好的自我
遇见更好的自我 2020-12-29 21:33

The Situation

I\'m using Visual Studio 2008 SP1 (Professional Edition, both for 32-bit and 64-bit builds). I\'m seeking a workaround to what I believe is

1条回答
  •  时光说笑
    2020-12-29 22:07

    I'm only answering to make it clear your feeling to not use static libraries is correct.

    DLRdave said it already in the comments, your build system is being abused by LIB files. A LIB file is much like a real library, you only walk out with the things you ask for, not everything in the library.

    If there's a gap in the Visual Studio 2008 tool set, it's that it doesn't support partial linking. The input into a partial link is a set of OBJ files and the output is a single OBJ file that contains all the code and data from the input OBJ files.

    The difference between an archive/library and a partial link is described for g++ in the answer to this question: g++ partial linking instead of archives?, where the GNU linker (ld) does support partial linking.

    As for possible short term mitigation - personally, I would have tried to use scripting to dynamically build the DEF file at build time by using LIB /List or DUMPBIN /ARCHIVEMEMBERS to get the obj files and LIB /DEF to generate the DEF file from that list. Or, as I assume _declspec(dllexport) is being used, you could have also used DUMPBIN /DIRECTIVES, looked for /EXPORT and built the DEF file yourself.

    0 讨论(0)
提交回复
热议问题