Removing the C run-time library (RTL)

2006-10-30 | Removing the C run-time library (RTL)

Removing the C run-time library (RTL)

This is pretty straight forward. Just click on the "Ignore all default libraries" in the Link tab in your project settings, or use the "/NODEFAULTLIB" linker setting. However, you probably wont be able to compile your project any more.

Visual C++ requires that you provide three functions (for a normal C program): __purecall, new and delete. A C program requires malloc and free. Obviously, if you don't do ANY memory allocation then you don't need them. Here are minimal implementations of these functions:

void * __cdecl operator new(unsigned int bytes)
{
  return HeapAlloc(GetProcessHeap(), 0, bytes);
}

void __cdecl operator delete(void *ptr)
{
  if(ptr) HeapFree(GetProcessHeap(), 0, ptr);
}

extern "C" int __cdecl __purecall(void)
{
  return 0;
}

This just leaves the entry-point functions. Define which ever one is required by the type of executable you are building. At the very least, your entry-point function must call either main WinMain or DllMain.

int  __cdecl mainCRTStartup();
int  __cdecl WinMainCRTStartup();
BOOL __cdecl _DllMainCRTStartup(HINSTANCE, DWORD, LPVOID);

你可能感兴趣的:(c,function,delete,library,Allocation,linker)