Search code examples
c++static-librariesstatic-linkingmsvcrtcrt

Static CRT link


im trying to build my project and I want to link the windows CRT statically, but I find some errors trying to linking it,

I've included in the linking list these ones:

  • libcmt.lib
  • LIBCPMT.LIB
  • libucrt.lib
  • libvcruntime.lib

but I get these linking errors, saying that these symbols are missing:

  • __imp_copysignf
  • __imp__aligned_free
  • __imp__aligned_malloc
  • __imp_modf
  • __imp_modff

I've already added libucrt (which is where must be malloc functions but still giving errors), what lib am I missing?

EDIT: Im using Visual Studio 2017 15.4.4 targeting Windows 10 ver.10.0.16299.0


Solution

  • Double-check that you have also set the /MT compiler flag. If it is not set, it is possible that it defaults to dynamic linking setting. In that case, _MT preprocessor define is missing, which causes the compiler to use calls to dynamic runtime functions. You can see the __imp__ prefix that normally comes from DLL import libraries.