How do you create a freestanding C++ program?

后端 未结 7 908
予麋鹿
予麋鹿 2021-02-02 02:11

I\'m just wondering how you create a freestanding program in C++?

Edit: By freestanding I mean a program that doesn\'t run in a hosted envrioment (eg.

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 02:54

    Even with your clarification, the answer is that it depends -- the exact boot sequence depends on the hardware -- though there's quite a bit of commonality. The boot loader is typically loaded at an absolute address, and the file it's contained in is frequently read into memory exactly as-is. This means instead of a normal linker, you typically use a "linking locator". Where a typical linker produces an executable file ready for relocation and loading, a locator produces an executable that's already set up to run at one exact address, with all relocations already applied. For those old enough to remember them, it's typically pretty much like an MS-DOS .COM file.

    Along with that, it has to (of course) statically link the whole run-time that the program depends upon -- it can't depend on something like a DLL or shared object library, because the code to load either of those hasn't itself been loaded yet.

提交回复
热议问题