Anonymous user
Creating a C Library: Difference between revisions
Jump to navigation
Jump to search
m
Fixed a few typos.
[unchecked revision] | [unchecked revision] |
m (Fix typo) |
m (Fixed a few typos.) |
||
Line 1:
This tutorial will discuss implementing your own Standard C Library (libc). While implementing a minimal subset for kernel use is easy, it is considerably more work to implement sufficient functionality to port third party programs. You may wish to save yourself the effort and port an [[C_Library|existing C library]]. Before going ahead, you may wish to create a [[OS_Specific_Toolchain|OS Specific Toolchain]], which will allow us more control of the compiler. Note that this tutorial is somewhat ELF-specific, although the
= Building =
Line 105:
Creating your own C library has a number of advantages. For instance, you can finally add that useful fopen_http that the GNU libc maintainers rejected. You can also add a bunch of new, useful conversion specifiers to your printf. But before you get too carried away, you should spend a few minutes thinking about compatibility. For instance, if you do add your fopen_http and your user-space programs use it, then you just lost portability back to Linux. While you are still bootstrapping your operating system, it is very valuable to be able to run and test your user-space programs from your host operating system. It allows more rapid development and makes sure that your libc functions do the same as the ones on your host system. Rather than adding these new utility functions to libc, it may well be worth adding them to a new separate library, which is portable and works under your operating system and your host operating system.
Additionally, you should be very careful about changing semantics of existing libc functions or adding new functions to existing headers (namespace
Fortunately, you can find plenty of the relevant standards online. For instance, you can look at:
Line 133:
= C++ Compatibility =
Traditionally C++ programs can use the C headers, even though such headers are written in C and have C linkage. Unless you
Telling GCC that your headers understand C++ is as simple as adding the following to your OS-specific gcc/gcc/config/myos.h:
|