简体   繁体   中英

How can I use stdio and stdlib while compiling with nostdlib and nostdinc flags?

I have written a Makefile which compiles my mini-os with another application. I have to use -nostdioc and -nostdlib to compile them, but the problem is, that application is using stdio/stdlib functions and when I run my Makefile I get the error message that the functions used by my application cannot be found.

I tried to remove the -nostdlib -nostdioc but that did not work.

Here is the Makefile if anyone would like to take a look.

-nostdlib tells gcc to not include tells the compiler to not include the standard libraries, one of them being glibc (the GNU libc). -nostdinc tells the compiler not to use the standard paths for header files. The functions with prototypes in stdlib.h and stdio.h are part of libc which you have told the gcc not to use. Therefore you will need to implement them yourself or include a libc explicitly (some common ones to use for custom operating systems are newlib and uClibc). Which approach is easier depends on the functions being used. I should add that at this point if you are trying to compile an operating system and an application, even a static application, you might want to look into using a cross-compiler ( http://wiki.osdev.org/GCC_Cross-Compiler ) and if you can get that working the next step is your own toolchain which includes a libc ( http://wiki.osdev.org/OS_Specific_Toolchain ).

If implementing the necessary functions is not an option than your best bet is to use a full toolchain including your own libc. You cannot simply use the GNU libc as part of what libc is is a wrapper around the system calls and you would have to have a kernel that has a system call interface that is the same as the host operating system. Note that part of the process of porting a libc to your operating system is implementing the system calls. For newlib this includes but is not limited to write, read, open, close, fork and exec. If your application does not use these system calls you can simply implement dummy versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM