2014
10-05

how to compile 64KB exe in visual 2012 without CRT

CRT (C Run Time) is library installed with visual studio that is usually required by exe files created by visual studio.
If you just copy exe file to other computer it may not work. You need to install on other computer CRT.
So if you want to create 64KB intro for demoscene that don't need any aditional dll's then you need to go around it.
They are few ways to do that:

1. Compile CRT into exe file (easy way).

In visual 2012 project go to Property Page / C/C++ / Code Generation and set Runtime Library to Multi-threated (/MT).
Next after compiling your program use Mew11 exe compressor to compress your exe file.

You will lost a lot of file size, by doing so. But it will work.

2. Don't use CRT at all

So what does it mean to not use CRT ? You may checking your exe in notepad and search for MSVCR110.dll or other MSVCR. Mostly what you need in your code is: - Don't use anything from std namespace. - Don't use standard functions like: malloc, free, sin, cos, time, srand, rand, printf, sprintf, scanf, sscanf, etc. - Don't use C++ keywords "new", "delete", "virtual". New and delete are just using malloc and free. - Don't use large local arrays. Use global or static.

3. Use Visual Studio v6.0 libs

Visual studio v6.0 use to use CRT witch is normally installed in every Windows. So the simplest way to do will be use visual studio 6. But it's not a nice editor so you may want to use new Visual studio 2012 (I personaly don't like visual 2013). In that case you may just create library project in Visual studio 6 with your own versions of all functions that you need. For example:
  1. #include <math.h>
  2. double mysqrt(double x){return sqrt(x);}
  3.  
Compile it, copy to your Visual Studio 2014 project directory, and add *.lib or *.obj from Visual 6 to your new project in visual 2014 to Property / Linker / Input / Additional Dependences. Then instead of using sqrt use mysqrt.
Comments are closed.