Search code examples
c++native

Compile C++ without CRT


Basically the title says it all; I want to COMPLETELY disable the CRT when I am coding in C++.

I want to be able to run the exe on Win98 as well as all the other ones. Just plain NATIVE C++.

The compiler I am using is Visual Studio. However, I am willing to change if it's required.


Solution

  • It's hard helping without knowing what you need to do, in general case you cannot remove CRT, here's why:

    • Entry point (gets input from console)
    • Provide common functions used in C and C++

    That means that without CRT you won't be able to use neither stdio (unless you link it later manually), also you cannot run the application in the console.

    A way you can remove CRT is by creating a static library, this is near to pure native C++ as much as possibile, if you don't link external libraries inside it (well, a object file is much more near to navite C++ than a static library).

    Depending on operative system you may not even be able to call a function within the binary without the CRT (in example Windows). So if you want just to avoid binary overhead the best bet is having a static/dynamic library wich is linked to some other "launcher" or just dynamically invoked (that needs a way to retrieve an entry point anyway).

    Again, hard to tell what you need if you don't give enough details.

    EDIT:

    If you need to run on older win98 then use a compiler that supports win98 and specify you want to compile for win98 using compiler flags.