vc编译去掉vcruntime140.dll依赖

为什么80%的码农都做不了架构师?>>>   hot3.png

属性-配置属性-c/c++-代码生成-运行库:多线程(/MT)

然后会发生一些诸如:

LNK2001 无法解析的外部符号 __except_handler4_common     msvcrt.lib

LNK2001 无法解析的外部符号 __imp__strstr

等问题。

__except_handler4_common:

The error message is actually saying the the function __except_handler4, defined in MSVCRT.LIB, references the undefined symbol __except_handler4_common. So it's not your code that's making the this reference, it's Visual Studio 2015's code.

The symbol __except_handler4_common is defined in vcruntime.lib. This file should be automatically be linked in. I'm not sure why it wasn't. Did you select the static runtime library in the project options ("Multi-threaded (/MT)"), but then manually add MSVCRT.LIB (part of the dynamic C runtime libary)

 

就把相应的库加入到:连接器-输入-附加依赖项, 就可以了,比如:libvcruntime.lib(注意:使用vcruntime.lib依然会依赖vcruntime140.dll,以lib开头的libxxx.lib才是真正的静态链接库)

__imp__strstr :

如果懒得找库,就直接声明一个,把vc自带函数封装进去就可以了,比如:

#ifdef __GNUC__
#elif defined(_MSC_VER)
//solve the problem of mingw64 cross compiling symble lost.
_CRT_STDIO_INLINE int __CRTDECL __ms_vsnprintf(
  _Out_writes_opt_(_BufferCount) _Always_(_Post_z_) char*       const _Buffer,
  _In_                                              size_t      const _BufferCount,
  _In_z_ _Printf_format_string_                     char const* const _Format,
  va_list           _ArgList)
{
  vsnprintf(_Buffer, _BufferCount, _Format, _ArgList);
  return 0;
}
_VCRTIMP char _CONST_RETURN* __cdecl __imp__strstr(
  _In_z_ char const* _Str,
  _In_z_ char const* _SubStr
)
{
  strstr(_Str, _SubStr);
  return 0;
}
#endif

 

转载于:https://my.oschina.net/u/1777508/blog/2246937

你可能感兴趣的:(vc编译去掉vcruntime140.dll依赖)