Compile C in Visual Studio 2012 without MSVCRT runtime

南楼画角 提交于 2019-12-23 20:32:16

问题


Visual Studio 2012 (and earlier versions) are capable of compiling C code. Plain C, not C++. It would be a good feature if you wanted to avoid the runtime hazzle. I thought of compiling plain C binaries and was hoping to do so without the MSVCRT runtime.

After adding the /TC (compile as C) option I was hoping to get a binary with only basic dependencies such as kernel32 and ntdll. But instead, this was linked:

We want to use VS 2012 and not the runtime. The GCC compiler doesn't need it, so there must be a way to compile a "simple" binary in VS, too. We don't necessarily need complex string functions or date/time libraries, just simple code.

Question: Is it possible to compile C code in Visual Studio 2012 without the MSVCRT runtime (or even C++ code) ?

Edit: without static linking (/MT)


回答1:


The correct answer to the question "Is it possible to compile C code in Visual Studio 20xx without the MSVCRT runtime (or even C++ code)?" is to use the /MT option (Configuration Properties > C/C++ > Code Generation > Runtime Library=Multi-threaded (/MT)). This creates an executable with no dependencies on any MSVCRTxx exactly as you wanted. As far as I know, that's all it does. It places no restrictions on anything you want to do - all the standard C library functions like memcpy still work. The only other difference is that the .EXE file is slightly larger. I've been making and distributing EXE files created like this from pure ANSI C code for years without any problems whatsoever using MSVC6, MSVC2005, MSVC2008 and MSVC2013.

As to the answer to the question with the qualifier "without static linking (/MT)", well, you can't.



来源:https://stackoverflow.com/questions/19072380/compile-c-in-visual-studio-2012-without-msvcrt-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!