如何通过CMAKE将Visual-Studio LinkLibraryDependencies属性设置为yes [英] How to set Visual-Studio LinkLibraryDependencies property to yes through CMAKE

查看:160
本文介绍了如何通过CMAKE将Visual-Studio LinkLibraryDependencies属性设置为yes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用cmake生成Visual Studio目标时,生成的项目文件在平台属性部分中包含以下内容:

  < ItemDefinitionGroup Condition ='$(Configuration)| $(Platform)'=='Debug | x64'> 
...
< ProjectReference>
< LinkLibraryDependencies> false< / LinkLibraryDependencies>
< / ProjectReference>
...
< / ItemDefinitionGroup>

我想从CMakeLists文件中将该属性设置为true。我该怎么做?



我的项目依赖项是使用 TARGET_LINK_LIBRARIES 设置的,但是在Linux上我也可以使用,例如:

  TARGET_LINK_LIBRARIES($ {targetname} -Wl,-Whole-archive * some libs *- Wl,-no-whole-archive),这会强制所有符号链接到目标中。 



使用Visual Studio链接所有符号的方法是指定:

 < LinkLibraryDependencies>真实< / LinkLibraryDependencies> 

通过项目设置。

解决方案

似乎不再需要链接库依赖项和使用库依赖项输入标志来链接所有lib符号。



在Visual Studio 2015中,您不能在目标上使用 / WHOLEARCHIVE 链接器标志。我编辑了一个相关问题的答案,以提供更多详细信息:



https://stackoverflow.com/a/23799529/1151329



该标志的作用类似于GCC -整个存档链接器标志。



在我的CMAKE文件中,我添加了以下内容:

  SET_TARGET_PROPERTIES($ {targetname}属性LINK_FLAGS_DEBUG / WHOLEARCHIVE:debug_lib_name)
SET_TARGET_PROPERTIES($ {targetname}属性LINK_FLAGS_RELEASE / WHOLEARCHIVE:release_lib_name)
>


When I generate a Visual Studio target with cmake, the generated project file contains the following in the platform properties section:

<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    ...
    <ProjectReference>
      <LinkLibraryDependencies>false</LinkLibraryDependencies>
    </ProjectReference>
    ...
</ItemDefinitionGroup>

I would like to set the property to true from the CMakeLists file. How do I do this?

My project dependencies are set up using TARGET_LINK_LIBRARIES, but on Linux I can also use, for example:

TARGET_LINK_LIBRARIES(${targetname} "-Wl,--whole-archive" *some libs* "-Wl,--no-whole-archive")

This forces all symbols to link into the target.

With visual studio the way to link all symbols is to specify:

<LinkLibraryDependencies>true</LinkLibraryDependencies>

through the project settings.

解决方案

It seems like the 'Link Library Dependencies' and 'Use Library Dependency Inputs' flags are no longer required to link all lib symbols.

In Visual Studio 2015 you can no use the /WHOLEARCHIVE linker flag on the target. I edited my answer to a related question to give more detail on this:

https://stackoverflow.com/a/23799529/1151329

The flag works like the GCC -whole-archive linker flag.

In my CMAKE file I added this:

SET_TARGET_PROPERTIES(${targetname} PROPERTIES LINK_FLAGS_DEBUG "/WHOLEARCHIVE:debug_lib_name")
SET_TARGET_PROPERTIES(${targetname} PROPERTIES LINK_FLAGS_RELEASE "/WHOLEARCHIVE:release_lib_name")

这篇关于如何通过CMAKE将Visual-Studio LinkLibraryDependencies属性设置为yes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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