How to set Visual-Studio LinkLibraryDependencies p

2019-07-23 16:02发布

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.

1条回答
beautiful°
2楼-- · 2019-07-23 16:34

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")
查看更多
登录 后发表回答