Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile C in Visual Studio 2012 without MSVCRT runtime

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:

enter image description here

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)

like image 935
bytecode77 Avatar asked Dec 02 '25 21:12

bytecode77


1 Answers

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.

like image 123
David I Avatar answered Dec 05 '25 10:12

David I



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!