Druntime: Changing the underlying C Standard Library

Adam D. Ruppe destructionator at gmail.com
Fri Jan 12 03:28:22 UTC 2018


On Friday, 12 January 2018 at 03:21:15 UTC, Sebastian Trent wrote:
> I'm writing an operating system in D for some exotic hardware. 
> I understand the D runtime environment depends on a C stdlib 
> being available (at compile time or run time?)

both

> As a consequence of the hardware, I need to use our own C std 
> lib for the operating system. How can I set about directing the 
> compiler (or run-time) to non-default implementation?

Same way you would in C itself: instruct the linker to use your 
runtime instead. On Linux, something like `-L-nostdlib 
-L-lmy_c_library` should do it. The -L option to dmd passes the 
rest of the option down to the linker (gcc, which then passes it 
to ld), so that `-nostdlib` flag is actually one of gcc's.

> Alternatively, I infer there's nothing breaking about replacing 
> all of core.stdc with an implementation written in -betterC?

core.stdc has no code per se, it is just function prototypes to 
access the C library. The C library itself is provided externally 
by the linker.


More information about the Digitalmars-d-learn mailing list