-
Notifications
You must be signed in to change notification settings - Fork 67
MSVC static runtime library #63
Comments
@jsutes Here is a minimal example of my CMakeLists.txt file. With it I download and build the Unfortunately, I can't build the set(BUILD_SHARED OFF CACHE INTERNAL "Build CryptoPP SHARED libraries") To set(BUILD_SHARED ON CACHE INTERNAL "Build CryptoPP SHARED libraries") I get this build error build_cryptopp_shared_error.txt Does anyone know what cryptopp-cmake CMake variable I should set to build the shared library? My environment info: |
CMake is a royal pain in the $%&.
You can zip |
You are right and I've updated my post. |
Thanks for the comments.
So far when I want to use cryptopp as a shared library, I've been using vcpkg. You say your compiler is MSVC but your error txt file looks like your using mingw32-make as the build tool. Is that allowed? I've only used Ninja or Visual Studio as the build tool with MSVC and CMake. In summary, I'm fine if this issue is closed since it's no longer a problem for me. But maybe it should be kept open until an option is added to toggle static/dynamic C/C++ runtime linking. |
Thanks for point that out. It was the remaining of my attempts to compile using _MSYS2_s GNU compiler with
I couldn't make it compile using Ninja in Visual Studio Community 2019 and Visual Studio Code, I was getting the error If I try to build Severity Code Description Project File Line Suppression State Error LNK1104 cannot open file '_deps\cryptopp-build\Debug\cryptopp-shared.lib' <path_to_project>\out\build\x64-Debug (Standard)\hmmenc_client <path_to_project>\out\build\x64 Debug (Standard)\LINK 1 Only cryptopp-shared.dll, cryptopp-shared.ilk and cryptopp-shared get created in <path_to_project>\out\build\x64-Debug (Standard)_deps\cryptopp-build\Debug |
Crypto++ DLL is probably not going to work. Under Visual Studio it is actually a FIPS DLL and it is a lot of trouble. My advice is, remove anything that has to do with a DLL. If you want a DLL, then create a Wrapper DLL with the functions you want to use. With that said, I don't know what the CMake folks are doing. I keep this repository open so there's a central location for CMakeFileList.txt. People can callborate on it, and folks know the place to download it. |
According to https://www.cryptopp.com/wiki/Visual_Studio cryptopp should favor static linking against the C/C++ runtime (/MT or /MTd).
When I use this cmake project with visual studio or ninja generator, I keep getting dynamically linked runtime. You can test this by searching the build.ninja output file for "\MD" or "\MT".
My cmake command is
How can we switch between static and dynamic linking with this project?
According to https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html#variable:CMAKE_MSVC_RUNTIME_LIBRARY and https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
we should be able to use
CMAKE_MSVC_RUNTIME_LIBRARY
as a global variable orMSVC_RUNTIME_LIBRARY
as a target specific property to choose the desired option. I tried setting these variables to "MultiThreaded" but it did not have an effect (I do successfully use these variables in my own projects).I was able to do a find-and-replace "/MD" to "/MT" in the build.ninja file and successfully built with static linked runtime library, so there shouldn't be issues with the build. We just need to figure out how to switch between the two in cmake instead of having to manually edit the ninja or visual studio output file.
OS: Windows 10
Compiler: MSVC/14.28.29333
CMake: 3.19
The text was updated successfully, but these errors were encountered: