[CMake] How to Switch to Static Runtime on Command Line?
Juan Sanchez
juan.e.sanchez at gmail.com
Mon Oct 28 12:46:08 EDT 2019
Hello,
It has been a while since I've looked at this stuff, but I do use
exceptions in my project. So I add the /EHsc:
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:strict /EHsc
${WARNINGS_IGNORE}")
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fp:strict ${WARNINGS_IGNORE}")
and I also add a linker flag:
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO
/NODEFAULTLIB:python3")
SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
According to the M$ documentation, SAFESEH is relevant for x86, but not x64:
https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers?view=vs-2019
In order to change runtimes, I have also had to enable defaultlib's in case
they got in through other libraries or header files:
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
/NODEFAULTLIB:LIBCMT")
According to this instruction you can disable all of the libraries you do
not want:
https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4098?view=vs-2019
For example, above I had to do:
/NODEFAULTLIB:python3
because the Python header files in my project were force linking the wrong
library.
Regards
On Mon, Oct 28, 2019 at 6:02 AM Osman Zakir <osmanzakir90 at hotmail.com>
wrote:
> Hi.
>
> I'm trying to build LLVM 10.0.0 with CMake on the command line (Developer
> Command Prompt for VS2019) and I need to know how to switch to a static
> runtime. I've tried specifying LLVM's variable for this, but it didn't
> work. I still have a dynamic runtime. Along with that, I also need to
> know how to enable C++ exceptions.
>
> One thing I tried was to do "-DCMAKE_CXX_FLAGS="/std:c++17 /MT /EHsc
> /permissive-"" but this also didn't work. Specifying these on the CXXFLAGS
> environment variable didn't do anything either. I was using the same
> session of the Developer Command Prompt, but I made sure to run
> "refreshenv" to take the new environment from the registry before
> continuing.
>
> Note: I don't want to edit the CMakeLists.txt file because I want to be
> able to run "git pull" without having to stage any changes (I cloned the
> LLVM GitHub repository for the source code).
>
> Any help is appreciated. Thanks in advance.
> --
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191028/ddeeb126/attachment.html>
More information about the CMake
mailing list