使用CMake 2.8.x将多个静态.lib文件链接到使用VS2008 SP1的一个单片.lib文件 [英] Linking multiple static .lib files into one monolithic .lib file using VS2008 SP1 using CMake 2.8.x

查看:713
本文介绍了使用CMake 2.8.x将多个静态.lib文件链接到使用VS2008 SP1的一个单片.lib文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关于使用cmake将对象文件链接到lib.xxxx.a文件,但不是完全相同的事情,我在Windows上使用CMake 2.8.x使用VS2008 SP1构建了几个静态库。有没有办法通过CMake单独重新链接所有这些现有的静态库中的所有.obj文件到一个更大的单片库,最好通过 add_library CMake函数或其他类似的结构?



我认为答案是no,所以我想通过一个自定义命令通过通常的 add_custom_command + + add_custom_target 方法,通过提供所有其他库.obj文件.EXE 。但我看到这种方法的一些问题:


  1. 我找不到一个CMake变量,指示<$ c的完全限定路径$ c> LINK.EXE 可执行文件。然后我会以某种方式导出使用脆弱的启发式的 LINK.EXE 的路径:这是脆弱的意思,不同的Visual Studio版本可能会找到 LINK.EXE 文件在不同的目录,我需要这个工作在32位和64位Windows编译器条件,并有弹性VS2008之间的升级和未来的编译器修订。 / li>
  2. 我需要找到一种方法来查找其他静态库的所有.obj文件,在构建时在CMake时 em>,因为在CMake时.obj文件当然不存在。由于构建性能的原因,我希望不要求从.lib文件中提取.obj文件,以便将它们添加到 LINK.EXE 命令行, c> c> c> c> LINK.EXE via: LINK.EXE /OUT:monolithic.lib lib1.lib lib2.lib ... 但也许不是所有的.obj的将包括(编辑:我已经确认 LINK.EXE 省略一些.obj文件从 lib1.lib lib2.lib ... ,没有任何诊断消息解释为什么,所以这种方法是非初始);关于 LINK.EXE 的在线文档尚不清楚。任何人都有以这种方式使用 LINK.EXE 的任何经验?



Brent



PS,我知道如何使用CMake创建一个DLL,但我不想

解决方案

使用虚拟源文件创建静态库合并并添加要合并到SITIC_LIBRARY_FLAGS的库,因此它们将是lib.exe的其他输入。



这将是:



ADD_LIBRARY(合并的STATIC dummy.c)



SET_TARGET_PROPERTIES(合并的属性

STATIC_LIBRARY_FLAGSfull\path\to\lib1.lib full\path\to\lib2.lib)

这种方法在MySQL内部使用,这里有一个更通用的宏来合并工作于crosss-platform的静态库。您可以在这里找到 http://www.mail-archive。 com / cmake@cmake.org/msg28670/libutils.cmake


Related to using cmake to link object files into lib.xxxx.a file, but not quite the same thing, I have built several static libraries on Windows using CMake 2.8.x using VS2008 SP1. Is there a way via CMake alone to relink all of the .obj files inside all of those existing static libraries into one larger monolithic library, preferably via the add_library CMake function, or other similar construct?

I think the answer is "no", and so I have thought about rolling my own via a custom command via the usual add_custom_command + add_custom_target approach, that simply constructs the library manually, by supplying all of the other libraries .obj files when calling LINK.EXE. But I see some problems with that approach:

  1. I could not find a CMake variable that indicates the fully-qualified path to the LINK.EXE executable. I would then have to somehow derive the path to LINK.EXE using a fragile heuristic: It is fragile in the sense that different Visual Studio versions may locate the LINK.EXE file in different directories, and I'm needing this to work for both 32-bit and 64-bit Windows compiler conditions, and be resilient against upgrades between VS2008 and future compiler revisions.
  2. I would have to find a way to find all of the .obj files of the other static libraries, at build time versus at CMake time, since at CMake time the .obj files of course do not (always) exist. For reasons of build performance, I desire not to resort to extracting the .obj files from the .lib files for the sake of adding them to the LINK.EXE command line, so a FILE(GLOB...) construct would be my best second alternative in this case.
  3. It may be possible to simply call LINK.EXE via: LINK.EXE /OUT:monolithic.lib lib1.lib lib2.lib ..., but maybe not all .obj's will be included (EDIT: I have confirmed that LINK.EXE omits some .obj files from lib1.lib lib2.lib ... without any diagnostic messages explaining why, so this approach is a non-starter); the online docs for LINK.EXE are unclear as to that point. Anyone have any experience with using LINK.EXE in that manner?

Thanks,

Brent

P.S., I know how to create a DLL using CMake, but I specifically do not want to resort to building a DLL at this point in time.

解决方案

Create a static library "merged" with a dummy source file, and add libs to be merged to the STATIC_LIBRARY_FLAGS, so they will be additional input to lib.exe.

This would be something like:

ADD_LIBRARY(merged STATIC dummy.c)

SET_TARGET_PROPERTIES(merged PROPERTIES
STATIC_LIBRARY_FLAGS "full\path\to\lib1.lib full\path\to\lib2.lib")

This approach is used inside MySQL, there is a more general macro here to merge static libraries that works crosss-platform. It can be found here http://www.mail-archive.com/cmake@cmake.org/msg28670/libutils.cmake

这篇关于使用CMake 2.8.x将多个静态.lib文件链接到使用VS2008 SP1的一个单片.lib文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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