c++ runtime
c++ runtime
How do you tell g++ to use a custom c++ runtime? And I assume you can tell it to statically link it?
Re:c++ runtime
Just make sure you don't link to any of the system libraries. In my experience, if you link using gcc or g++, this will happen automatically. If you link using ld then it won't do anything automatically.
If in doubt, pass -nostdlib to ld.
If in doubt, pass -nostdlib to ld.
Re:c++ runtime
You also cant use new or delete without a runtime. And I want those. I need to write a runtime. I know it is possible, and probably not much different from writing new and delete methods in some class. But I am not sure how to sell g++ what to use. If I dont use a runtime, I might as well use C (but I like C, so that not a problem. This is mostly curiosity)
Re:c++ runtime
If you've already got malloc and free, new and delete are easy. Just implement global new and delete operators in terms of malloc and free, and ld will use those.
Re:c++ runtime
Ah. Thanks. I dont really use c++ (prefer C usually). I did not know you could write your own new/delete.
Re:c++ runtime
You can do this with any C++ compiler, not just when writing your own OS.
This should do it:
This should do it:
Code: Select all
void *operator new(size_t bytes)
{
return malloc(bytes);
}
void operator delete(void *ap)
{
free(ap);
}