[cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS

Brad King brad.king at kitware.com
Tue Nov 5 11:57:30 EST 2019


On 11/5/19 7:30 AM, Alexander wrote:
> string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"foo_1.def\" -DEF111:\"foo_1.def\"")

This was the first you've mentioned using more than one copy of the flag.

I tested with this:

```
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/foo.def\"")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/bar.def\"")
```

With the command-line generators like Ninja or NMake Makefiles, both flags
appear.  With the Visual Studio generators, only the latter flag appears.

The reason is that CMake maps the `-DEF:` linker flag to the `.vcxproj`
file element `ModuleDefinitionFile` but only puts one value in it.  The
MSBuild documentation for that field is here:

  https://docs.microsoft.com/en-us/visualstudio/msbuild/link-task?view=vs-2019

and says "Specifies the name of a module definition file."  AFAIK it only
supports one value.  This is a limitation of MSBuild.

-Brad


More information about the cmake-developers mailing list