Visual Studio 2015:在没有运行时库的情况下编译C / C ++ [英] Visual Studio 2015: Compile C/C++ without a runtime library
问题描述
是否可以在不使用任何运行时库的情况下使用Visual Studio 2015编译C / C ++?
Is there a way of compiling C/C++ with Visual Studio 2015 without using any runtime library?
我需要在没有运行时库的情况下进行编译,因为我正在创建我自己的运行时库(适用于我的操作系统)。
I need to compile without a runtime library because I'm creating my own runtime library (for my OS).
C / C ++->代码生成->运行时库
有一些选项,但是我想要
There are options on C/C++->Code Generation->Runtime Library
but I want an option that says "none".
我知道失去了CRT中的许多功能。
I'm aware of loosing a lot of features that are in the CRT.
推荐答案
要在不使用C运行时库(CRT)的情况下编译您的应用,请使用 / MT
, / NODEFAULTLIB
链接器选项,并在 Linker->中重新定义入口点。进阶->进入点
,以实现代码中定义的功能,例如 rawMain
。签名是:
To compile your app without C-Runtime Library (CRT) use /MT
, /NODEFAULTLIB
linker options and redefine entry point at Linker -> Advanced -> Entry Point
to function defined in your code, e.g. rawMain
. The signature is:
DWORD CALLBACK rawMain();
没有C运行时库,则不允许使用它的功能,例如 malloc
,免费
,内存集
等。您应通过以下方式实现所有使用的CRT功能:你自己例如。您可以将 malloc
的用法替换为 VirtualAlloc()
和 free
通过 VirtualFree()
。
Without C-runtime library you are not allowed to use it's functions, like malloc
, free
, memset
, etc. You should implement all the used CRT functions by yourself. E.g. you can replace usage of malloc
by VirtualAlloc()
and free
by VirtualFree()
.
要检查C运行时是否未链接到您的应用程序,请使用 Dependency Walker 。
To check that C-runtime is not linked to your application use Dependency Walker.
这篇关于Visual Studio 2015:在没有运行时库的情况下编译C / C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!