精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>嵌入式开发>>翻译计划《写你自己的操作系统》(C程序库)

主题:翻译计划《写你自己的操作系统》(C程序库)
发信人: zelor(东村遗少张作乐)
整理人: wenbobo(2003-01-09 14:57:35), 站内信件
Where did my printf go? 
我的printf跑到了哪里?

So your kernel is nothing but a simple 
你的核心非常简单:

/* my test kernel */
void main(void)
{
printf("test\n");
}

But it wont link! It complains of missing printf. 
但这不能够link!连接器会报错:找不到printf。

When you write an OS, the compiler has several libraries of function 

calls (printf, fopen, fread, memmove, strcmp, etc) that are built to 

run on that particular operating system. Basically, you are trying to 

use a routine that is not part of your os. 
当你写一个操作系统时,编译器有一些函数调用库(比如printf, fopen, fread, 

memmove, strcmp,等等),这些库是为特定的操作系统建立和运行的。这些例程

并不是你写的操作系统的一部分。

You have to write your own c library containing those calls for them to 

work on your operating system. see So whats this libc thing? 
因此你不得不自己完成自己的c库,用来包含你的操作系统中的系统调用。关于这

个问题,请看下一节。 

 

So whats this libc thing?
libc是干什么用的?
 
The libc is the compilers c library of function calls. If you want to 

use routines like printf, strcmp, strcopy, memmove, getch, toupper, etc 

in your operating system, you have to either port them over from an 

existing C library, or write them yourself. 
libc是编译的c函数调用库。如果你需要在你的操作系统里使用printf, strcmp, 

strcopy, memmove, getch, toupper等等函数,你必须将它们逐个从已存在的库

中移植过来,或者你自己写。

This includes the appropriate stdlib.h, string.h files as well as the 

routines themselves. 
其中包括了适当的stdlib.h和string.h,跟它们的例程一样好。 

 

What C libraries exist for me to use? 
我有什么现成的C程序库可以用?

There are some existing C libraries you can port to your OS (basically 

you just recompile them). 
有一些存在的C程序库可供你移植到你的OS上(最基本的情况你只需简单的重新编

译它们)。

Be aware some C libraries are copyright and some are free, some are 

gnu. 
首先明确的是一些C程序库是有版权许可的,而另一些是免费的,还有一些是gnu

的。

There exists a few GNU C libraries you can use. Be carefull not to use 

all the functions, as many have low level constraints (fopen, fread, 

etc) whereas a lot of it you can use, eg: memmove, isalpha, strcmp, 

etc. 
有许多存在的GNU C程序库可供你使用。注意不是所有的函数都能用,有许多包括

了底层的约束(比如fopen,fread等等),而另外许多你可以使用,比如memmove, 

isalpha, strcmp,等等。

Visual C comes with source for its C library, but ofcourse it is 

copyright so be veeeeeery carefull if you want to err try and use that 

as your own library source. 
Visual C 中包含有其C程序库的源代码,但毫无疑问,它是有版权的,所以如果

你打算在你的库中使用它,而又不想犯错误的话,你必须非——常小心。 



----
生活,就是理想加泡面。
                    ——张作乐,送你一束玫瑰   
        

[关闭][返回]