Visual Studio 2015: Compile C/C++ without a runtime library

久未见 提交于 2019-12-05 15:38:51

问题


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).

There are options on C/C++->Code Generation->Runtime Library
but I want an option that says "none".

I'm aware of loosing a lot of features that are in the CRT.


回答1:


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();

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().

To check that C-runtime is not linked to your application use Dependency Walker.



来源:https://stackoverflow.com/questions/39217241/visual-studio-2015-compile-c-c-without-a-runtime-library

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