0

I've been programming C for a while with Visual Studio, but now switched to CLion. My programming and target system is Windows10.

Within Visual Studio, I was able to include the required DLLs like "vcruntime140d.dll" and "ucrtbased.dll" inside my exe.

I did this by going into the project settings and set configuration settings - C/C++ - code generation - runtime library to "Multithreaded-Debug (/MTd)". Doing this I was able to run the resulting exe without having errors like "vcruntime140d.dll is missing" or "ucrtbased.dll is missing".

But how can I achieve this within CLion?

I've been searching for a while now, and I found a lot of tutorials on how to include .lib files but not for DLLs (I don't have the code for).

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Id3aFly
  • 1
  • 1
  • Which compiler are you using with CLion? MSVC? The option is still `/MTd`, if you want to use the debug runtime.. GCC, Clang, something else? The option you're looking for will be "statically link runtime" or similar, e.g. [-static](https://stackoverflow.com/a/26107550/243245) for the link step in GCC at least, if not Clang as well. Or you can just switch to using the release runtimes, which in general everyone will have installed already. – Rup Sep 15 '20 at 11:35

1 Answers1

1

With Clion, you actually are working with CMake. So the question is to be like how to link dlls within CMake.

There are many ways to do. e.g.

If the library could not be found by default, use find_library to search for it.

If these functions seems too strange to you, check this tutorial from the CLion team.

Update

As in the comment you asked, your problem is how to load a dll without lib. To address this, you could dynamicly load the dll, or make a lib from the dll.

For Windows multicopies problem, add following into your CMakeLists.txt

foreach (flag_var
      CMAKE_C_LINK_FLAGS
      CMAKE_C_LINK_FLAGS_DEBUG
      CMAKE_C_LINK_FLAGS_RELEASE
      CMAKE_CXX_LINK_FLAGS
      CMAKE_CXX_LINK_FLAGS_DEBUG
      CMAKE_CXX_LINK_FLAGS_RELEASE
      CMAKE_EXE_LINKER_FLAGS
      CMAKE_EXE_LINKER_FLAGS_DEBUG
      CMAKE_EXE_LINKER_FLAGS_RELEASE
      CMAKE_C_FLAGS
      CMAKE_C_FLAGS_DEBUG
      CMAKE_C_FLAGS_RELEASE
      CMAKE_C_FLAGS_MINSIZEREL
      CMAKE_C_FLAGS_RELWITHDEBINFO
      CMAKE_CXX_FLAGS
      CMAKE_CXX_FLAGS_DEBUG
      CMAKE_CXX_FLAGS_RELEASE
      CMAKE_CXX_FLAGS_MINSIZEREL
      CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
endforeach ()
Galaxy
  • 1,129
  • 11
  • 27
  • Thanks! The question is actually about turning on static linking though, i.e. linking the runtime libraries into the built .exe, if you know about that? – Rup Sep 16 '20 at 13:57
  • You can [dynamicly load the dll](https://stackoverflow.com/questions/8696653/dynamically-load-a-function-from-a-dll). Or [turn it into a lib](https://stackoverflow.com/questions/9360280/how-to-make-a-lib-file-when-have-a-dll-file-and-a-header-file) first. – Galaxy Sep 16 '20 at 13:59