红联Linux门户
Linux帮助

GeekOS编译于64位Linux系统

发布时间:2014-12-09 21:38:10来源:crazyjixiang作者:crazyjixiang

开始GeekOS之旅的时候,一开始就碰到了小麻烦,在自己64位的Fedora上编译GeekOS的时候报如下错误:

geekos/lowlevel.o: could not read symbols: File in wrong format


断定是平台问题.再去官网看了下:

GeekOS is a tiny operating system kernel for x86 PCs. 

看了后就决定换i386系统了,装上后就发现很多需要配置,太麻烦,稍微思考片刻,记得以前在编译其它i386代码时,是可以跨平台的,编译时搜索lib32库不就行了嘛.研究了下GeekOS的Makefile.


GeekOS提供的Makefile中是有编译于X64的配置的.拿 project0的Makefile来说,在第97行(GeekOS-0.3.0) 把TARGECT_CC_PREFIX打开就可以了. 但是你的OS需要安装Cross-development的开发包.

不过没关系,还有个方法就是加编译选项 -m32 和 链接选项 -m elf_i386 这样会在编译时自动去找lib32.在GeekOS的 Makefile中第100,106,109行改成如下:


100 TARGET_CC := $(TARGET_CC_PREFIX)gcc -m32                                                   
101  
102 # Host C compiler.  This is used to compile programs to execute on                         
103 # the host platform, not the target (x86) platform.  On x86/ELF 
104 # systems, such as Linux and FreeBSD, it can generally be the same                         
105 # as the target C compiler.                                                                
106 HOST_CC := gcc -m32                                                                        
107  
108 # Target linker.  GNU ld is probably to only one that will work.                           
109 TARGET_LD := $(TARGET_CC_PREFIX)ld  -m elf_i386
            

然后改动后,你可能需要安装glibc的386版本,fedora安装如下:

yum -y install glibc-devel.i686


然后再进行编译就OK了:

cat geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin > fd.img

镜像文件成功生成.