1
votes

I am trying to use IUP to create a gui program in Windows 10. I am also using Clion+MSVC as an IDE. IUP has both .lib and .dll files for download and all goes well when I don't specify how to link in cmake; cmake automatically tries to link dynamically with iup.dll when there are no custom flags about linking.

However, when I try to statically link iup.dll with a compiler flag /MT, the compiler automatically changes /MT to /MD and just link dynamically.

Here's the cmake code I used to force compiler static linking:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")

and then I get this warning:

cl : Command line warning D9025 : overriding '/MT' with '/MD'

Any way to "force" cmake and compiler to statically link library to my program?

3
Possible duplicate of stackoverflow.com/questions/10113017/…vre

3 Answers

0
votes

Cmake had commands to automatically set almost all these flags.

Try adding add_library(iup.dll STATIC IMPORTED) before the target_link_libraries

Cmake doc

0
votes

By default CMake uses the MSVC dynamic runtime library (/MD) when building static or shared libraries.

You need to replace the /MD setting in the CMAKE_C_FLAGS/CMAKE_CXX_FLAGS variables with /MT. This can be done by the follwoing commands:

string(REGEX REPLACE "/MD" "/MT" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

For a complete solution please see the following post

0
votes

Another options:

set_target_properties(TARGET_LIB PROPERTIES
    COMPILE_OPTIONS "$<$<CONFIG:Debug>:/MTd>$<$<CONFIG:Release>:/MT>"
    )