libzmq
libzmq copied to clipboard
cmake cannot generate zeromq.sln with default runtime environment to /MT
Please use this template for reporting suspected bugs or requests for help.
Issue description
When using cmake to generate the zeromq.sln, the default option is /MD.
By opening the zeromq.sln we can change it to /MT and all is fine. However when MSBuild.exe is used to build the zeromq-static project, it is not possible to override the /MD value and set it to /MT.
Trying to set CL=/MT and then running the MSBuild.exe shows that
"Command line warning D9025: overriding '/MD' with '/MT' [C:\zeromq\libzmq\vs\libzmq-static.vcxproj]"
However when trying to link to the produced library from a project with static runtime we are getting the following linking error:
"Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Zeromq.obj Zeromq ...\libzmq-v141-mt-s-4_3_3.lib(zmq.obj) 1 " It seems that by just overriding /MD with /MT via the %CL% does not work.
Would it be possible to add support for static runtime in the CMakeList.txt?
Environment
- libzmq version (commit hash if unreleased): master
- OS: windows 10
Minimal test code / Steps to reproduce the issue
-
cmake -H. -Bvs -G"Visual Studio 15 2017 Win64" -DCMAKE_SYSTEM_VERSION=10.0 -DENABLE_CURVE=OFF -DZMQ_BUILD_TESTS=OFF -DBUILD_SHARED=OFF
-
set CL=/MT
-
MSBuild.exe ZeroMQ.sln /p:configuration=release /p:platform=x64 -target:libzmq-static
-
Create a static runtime project and link to the libzmq-v141-mt-s-4_3_3.lib
What's the actual result? (include assertion message & call stack if applicable)
"Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Zeromq.obj Zeromq ...\libzmq-v141-mt-s-4_3_3.lib(zmq.obj) 1 "
What's the expected result?
To link without any issues
After experiencing this problem myself, and spend quite some time "where is there a switch/option/setting to enable 'static runtime-library'?", I ended up using some of the setup from protobuf's CMakeLists.txt (Search for /MT
to locate the relevant "code".)
Also found some information at https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-build-my-msvc-application-with-a-static-runtime which helped, in particular the 'Dynamic Replace' section.
This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.
I am currently experiencing this issue, trying to find out a proper solution, since building libzmq is jsut part of a bigger building toolchain, so editing the pregenerated sln file is not an option
Okay, i found a way to do it from command line arguments, it depends if you are building debug or release static library: (Note: i am runing cmake as a dependency inside of a scons toolchain)
if env_zmq["target"] == "template_debug":
cmake_opts += " -DCMAKE_CXX_FLAGS_DEBUG=\"/MTd\" "
else:
cmake_opts += " -DCMAKE_CXX_FLAGS_RELEASE=\"/MT\" "
The final cmake and msbuild command looks as follows:
cmake -DCMAKE_BUILD_TYPE=Release -DZEROMQ_CMAKECONFIG_INSTALL_DIR=CMake -DZEROMQ_LIBRARY=libzmq -DZMQ_BUILD_TESTS=OFF -DZMQ_CV_IMPL=stl11 -DZMQ_OUTPUT_BASENAME=zmq -DZMQ_OUTPUT_BASENAME=zmq -DBUILD_SHARED=OFF -DBUILD_STATIC=ON -DZMQ_STATIC=ON -DBUILD_TESTS=OFF -DENABLE_ANALYSIS=OFF -DENABLE_ASAN=OFF -DENABLE_CLANG=ON -DENABLE_CPACK=OFF -DENABLE_CURVE=OFF -DENABLE_DRAFTS=OFF -DENABLE_EVENTFD=OFF -DENABLE_INTRINSICS=OFF -DENABLE_PRECOMPILED=OFF -DENABLE_RADIX_TREE=OFF -DENABLE_TSAN=OFF -DENABLE_UBSAN=OFF -DENABLE_WS=OFF -DLIBZMQ_PEDANTIC=ON -DLIBZMQ_WERROR=OFF -DWITH_DOCS=OFF -DWITH_LIBSODIUM=OFF -DWITH_LIBSODIUM_STATIC=OFF -DWITH_MILITANT=OFF -DWITH_NORM=OFF -DWITH_OPENPGM=OFF -DWITH_PERF_TOOL=ON -DWITH_VMCI=OFF -DCMAKE_CXX_FLAGS_RELEASE="/MT" -S D:/work/astera-app/modules/zeromq/thirdparty/libzmq-4.3.4 -B D:\work\astera-app\modules\zeromq\thirdparty\build\windows
msbuild D:\work\astera-app\modules\zeromq\thirdparty\build\windows\libzmq-static.vcxproj /p:OutDir=D:\work\astera-app\modules\zeromq\thirdparty\lib\windows/ /p:TargetName=zmq /p:Configuration=Release