Re: [cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS
Thank you very much, Brad. I found that WINDOWS_EXPORT_ALL_SYMBOLS was set in my CMakeLists.txt. After I removed it the /DEF parameter from CMAKE_SHARED_LINKER_FLAGS appeared in the linking command. -- Best Regards, Alexander On Fri, 8 Nov 2019 at 14:52, Brad King wrote: > On 11/8/19 5:17 AM, Alexander wrote: > > > /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). > > That behavior is not default, but activated by > CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS: > > > https://cmake.org/cmake/help/v3.16/variable/CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS.html > > The project you're building must be using that setting. Find it and turn > it off. > > -Brad > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake-developers
Re: [cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS
On 11/8/19 5:17 AM, Alexander wrote: > /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). That behavior is not default, but activated by CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS: https://cmake.org/cmake/help/v3.16/variable/CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS.html The project you're building must be using that setting. Find it and turn it off. -Brad -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake-developers
Re: [cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS
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 https://docs.microsoft.com/en-us/cpp/build/reference/def-specify-module-definition-file?view=vs-2019 : """ The /DEF option passes a module-definition file (.def) to the linker. Only one .def file can be specified to LINK. """ In reality you can pass multiple /DEF to the linker, but it uses the last one. 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). 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. 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: - CMAKE_CXX_STANDARD_LIBRARIES adds custom /DEF parameter before the default /DEF:exports.def that does not help - 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) So, does CMake provide a way to override the value of the default /DEF: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? -- Best Regards, Alexander On Tue, 5 Nov 2019 at 17:57, Brad King wrote: > 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 > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake-developers
Re: [cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS
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 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake-developers
Re: [cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS
Well, I have tested this proposal as well and I can confirm that it does not work for me. I have added this code to my CMakeLists.txt: string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"foo_1.def\" -DEF111:\"foo_1.def\"") string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " -DEF:\"foo_2.def\"") # just in order to illustrate that CMAKE_CXX_STANDARD_LIBRARIES works with DEF: option in distinct to CMAKE_SHARED_LINKER_FLAGS As a result I see "-DEF:foo_2.def" (in the middle of the linking command right after the "standard" exports.def) and -DEF111:foo_1.def (at the and of the linking command), however I don't see "-DEF:foo_1.def" and it means it was stripped. I am not sure that it can be informative, but for the illustration I show the full linking command: Link: C:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /ERRORREPORT:QUEUE /OUT:"E:\workspace\cmake_test_option\tesseract\bin\bin\Release\tesseract41.dll" /INCREMENTAL:NO /NOLOGO Ws2_32.lib "E:\workspace\cmake_test_option\leptonica\bin\src\Release\leptonica-1.78.0.lib" "e:\workspace\cmake_test_option\libjpeg\libjpeg_a.lib" "e:\workspace\cmake_test_option\libpng\lib\libpng16_static.lib" "e:\workspace\cmake_test_option\libtiff\lib\tiff.lib" "e:\workspace\cmake_test_option\zlib\lib\zlibstatic.lib" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib *"-DEF:foo_2.def"* /DEF:"E:/workspace/cmake_test_option/tesseract/bin/libtesseract.dir/Release/exports.def" /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"E:/workspace/cmake_test_option/tesseract/bin/bin/Release/tesseract41.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"E:/workspace/cmake_test_option/tesseract/bin/Release/tesseract41.lib" /MACHINE:X64 /machine:x64 *-DEF111:foo_1.def* /DLL libtesseract.dir\Release\libtesseract.res It proves what I wanted to say that CMAKE_SHARED_LINKER_FLAGS strips -DEF: option in purpose, in distinct to CMAKE_CXX_STANDARD_LIBRARIES which accepts everything. For me it looks like a bug or like an undocumented behavior of CMAKE_SHARED_LINKER_FLAGS. -- Best Regards, Alexander On Thu, 10 Oct 2019 at 00:29, Brad King wrote: > On 10/9/19 6:04 PM, Alexander wrote: > > it deliberately ignores /DEF: which makes impossible to add /DEF: this > easy > > (and for me preferable) way. > > The code > > ``` > string(APPEND CMAKE_SHARED_LINKER_FLAGS " > -DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/foo.def\"") > ``` > > works fine for me. > > So does this: > > > ``` > target_link_options(mySharedLib PRIVATE > "-DEF:${CMAKE_CURRENT_SOURCE_DIR}/foo.def") > ``` > > -Brad > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake-developers
Re: [cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS
On 10/9/19 6:04 PM, Alexander wrote: > it deliberately ignores /DEF: which makes impossible to add /DEF: this easy > (and for me preferable) way. The code ``` string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/foo.def\"") ``` works fine for me. So does this: ``` target_link_options(mySharedLib PRIVATE "-DEF:${CMAKE_CURRENT_SOURCE_DIR}/foo.def") ``` -Brad -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake-developers
Re: [cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS
In some cases it is not convenient to program something in CMakeFile.txt (for example when I clone some 3rd party project and want to change its build procedure). Thus the possibility to add additional .defs files with the help of *command line* options would be very nice. Such a command line option exists: -DMAKE_SHARED_LINKER_FLAGS, but it deliberately ignores /DEF: which makes impossible to add /DEF: this easy (and for me preferable) way. I would like to get an answer from CMake developers, if it is an expected behavior of MAKE_SHARED_LINKER_FLAGS. If yes: what is the logic behind it and why this special handling of MAKE_SHARED_LINKER_FLAGS is not documented on https://cmake.org/cmake/help/v3.15/variable/CMAKE_SHARED_LINKER_FLAGS.html. If no: issue a bug. -- Best Regards, Alexander Do it mean that On Tue, 8 Oct 2019 at 16:57, Brad King wrote: > On 10/8/19 8:10 AM, Alexander wrote: > > I found that CMake ignores /DEF: option in CMAKE_SHARED_LINKER_FLAGS. > > I would like to know if this is an expected behaviour or a bug. > > A module definition file can be passed as a normal source file and > CMake will automatically add `/DEF:...` to the link line as needed. > > -Brad > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake-developers
Re: [cmake-developers] CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS
On 10/8/19 8:10 AM, Alexander wrote: > I found that CMake ignores /DEF: option in CMAKE_SHARED_LINKER_FLAGS. > I would like to know if this is an expected behaviour or a bug. A module definition file can be passed as a normal source file and CMake will automatically add `/DEF:...` to the link line as needed. -Brad -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake-developers