<div dir="ltr"><div>I am sorry that I did not make it clear from the beginning. You are right. Not only MSBuild, but MSVC linker (link.exe) accepts only one /DEF parameter according to <a href="https://docs.microsoft.com/en-us/cpp/build/reference/def-specify-module-definition-file?view=vs-2019">https://docs.microsoft.com/en-us/cpp/build/reference/def-specify-module-definition-file?view=vs-2019</a>:<br>"""<br>The /DEF option passes a module-definition file (.def) to the linker. Only one .def file can be specified to LINK.<br>"""<br></div><div>In reality you can pass multiple /DEF to the linker, but it uses the last one.</div><div><br></div><div>The problem is that the original /DEF parameter /DEF:"E:/workspace/cmake_test_option/tesseract/bin/libtesseract.dir/Release/exports.def" is added by CMake automatically and I cannot control it (CMake first creates a file objects.txt and then exports.def from it).</div><div>I wanted to override this parameter with a custom /DEF parameter, that means my /DEF parameter must be passed after that default one in the linking command.</div><div>However, as you can see from the linking command in my previous e-mail, I could not easily achieve this with the current CMake functionality, because:</div><div> - CMAKE_CXX_STANDARD_LIBRARIES adds custom /DEF parameter before the default /DEF:<build_path>exports.def that does not help<br></div><div> - CMAKE_SHARED_LINKER_FLAGS adds something to the end of the command, but only if this something is not /DEF (because one /DEF is already defined and CMake does not overwrite it, as you said earlier)<br></div><div><br></div><div>So, does CMake provide a way to override the value of the default /DEF:<build_path>exports.def or does it provide a way to pass my custom /DEF after the default one so that link.exe would use my custom /DEF parameter?<br></div><div></div><div><br></div><div>--</div><div>Best Regards,</div><div>Alexander<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 5 Nov 2019 at 17:57, Brad King <<a href="mailto:brad.king@kitware.com">brad.king@kitware.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 11/5/19 7:30 AM, Alexander wrote:<br>
> string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"foo_1.def\" -DEF111:\"foo_1.def\"")<br>
<br>
This was the first you've mentioned using more than one copy of the flag.<br>
<br>
I tested with this:<br>
<br>
```<br>
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/foo.def\"")<br>
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/bar.def\"")<br>
```<br>
<br>
With the command-line generators like Ninja or NMake Makefiles, both flags<br>
appear.  With the Visual Studio generators, only the latter flag appears.<br>
<br>
The reason is that CMake maps the `-DEF:` linker flag to the `.vcxproj`<br>
file element `ModuleDefinitionFile` but only puts one value in it.  The<br>
MSBuild documentation for that field is here:<br>
<br>
  <a href="https://docs.microsoft.com/en-us/visualstudio/msbuild/link-task?view=vs-2019" rel="noreferrer" target="_blank">https://docs.microsoft.com/en-us/visualstudio/msbuild/link-task?view=vs-2019</a><br>
<br>
and says "Specifies the name of a module definition file."  AFAIK it only<br>
supports one value.  This is a limitation of MSBuild.<br>
<br>
-Brad<br>
</blockquote></div>