本文介绍了在使用nostdlib和nostdinc标志进行编译时,如何使用stdio和stdlib?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Makefile,用另一个应用程序编译我的mini-os.我必须使用 -nostdioc -nostdlib 进行编译,但是问题是,该应用程序正在使用stdio/stdlib函数,当我运行Makefile时出现错误提示找不到我的应用程序使用的功能.

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.

我试图删除 -nostdlib -nostdioc ,但这没有用.

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

这是Makefile (如果有人想看看).

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

推荐答案

-nostdlib 告诉gcc不包括告诉编译器不包括标准库,其中一个是glibc(GNU libc). -nostdinc 告诉编译器不要对头文件使用标准路径.stdlib.h 和 stdio.h 中带有原型的函数是 libc 的一部分,您已告诉 gcc 不要使用它.因此,您将需要自己实现它们或显式包括一个libc(用于自定义操作系统的一些常见的是newlib和uClibc).哪种方法更简单取决于所使用的功能.如果要尝试编译操作系统和应用程序,甚至是静态应用程序,我应该补充一点,您可能希望使用交叉编译器( http://wiki.osdev.org/GCC_Cross-Compiler ),如果可以使下一步工作是您自己的工具链,其中包括一个libc( http://wiki.osdev.org/OS_Specific_Toolchain ).

-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).

如果不是实现必要功能的选择,那么最好的选择是使用包括您自己的libc在内的完整工具链.您不能简单地使用 GNU libc 作为 libc 的一部分,它是系统调用的包装器,您必须拥有一个内核,该内核具有与主机操作系统相同的系统调用接口.请注意,将libc移植到操作系统的过程的一部分是实现系统调用.对于newlib,这包括但不限于写入,读取,打开,关闭,派生和执行.如果您的应用程序不使用这些系统调用,则只需实现虚拟版本即可.

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.

这篇关于在使用nostdlib和nostdinc标志进行编译时,如何使用stdio和stdlib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 12:25