2014-11-06 30 views
0

我想交叉編譯一個簡單的程序,該程序在我的x86_64上使用libncurses。目標系統是MIPS。crosstool-ng - stdio.h:沒有這樣的文件或目錄

crosstool-ng-1.20構建了罰款(樣本MIPS-未知精靈)

但是,一個簡單的Hello World非常結束。

#include <stdio.h>  

int main(void)   
{       
    printf("OH HAI.\n"); 
    return 0;    
}    

-

x86host:~/toolchain$ mips-unknown-elf-gcc -o hello hello.c 

hello.c:1:19: fatal error: stdio.h: No such file or directory 
#include <stdio.h> 
       ^
compilation terminated. 

我清楚地做一些可怕的錯誤在這裏,但我從哪裏開始?


[編輯]

謝謝markgz。 Codesourcery正是我所需要的。

mips-linux-gnu-gcc.exe -static -o helloStatic hello.c 

概念驗證完成。現在編譯我的ncurses程序。

[Switch:/]$ file /mnt/sd3/user/helloStatic 
/mnt/sd3/user/helloStatic: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, 
statically linked, for GNU/Linux 2.6.16, with unknown capability 
0x41000000 = 0xf676e75, not stripped 

[Switch:/]$ uname -a 
Linux Switch 2.6.32.59-cavium-octeon2.cge-cavium-octeon #1 
SMP PREEMPT Fri May 10 11:48:14 PDT 2013 mips64 GNU/Linux 

[Switch:/]$ /mnt/sd3/user/helloStatic 
HOLIDAYS ARE COMING. 

回答

1

您可能需要構建mips-linux-elf-gcc。你確定你的MIPS目標系統配置爲big-endian嗎?

無論如何,您可以通過從here下載免費的Mentor/Codesourcery MIPS gnu/gcc交叉編譯工具鏈來避免所有這些問題。該工具鏈適用於Windows和Linux。

0
[email protected]:~/ncurses-5.9-20141101# export CC=mips-linux-gnu-gcc 
[email protected]:~/ncurses-5.9-20141101# ./configure --target=mips-linux-gnu --host=mips-linux-gnu 
[..] 
[email protected]:~/ncurses-5.9-20141101# make 

然後,我從/ usr/include中複製幾頭/讓這些走:

[email protected]:~/ninvaders-0.1.1# make 
In file included from ./ncurses.h:1685:0, 
      from view.h:25, 
      from view.c:25: 
./unctrl.h:54:20: fatal error: curses.h: No such file or directory 
#include <curses.h> 
       ^
compilation terminated. 
make: *** [view.o] Error 1 


[email protected]:~/ninvaders-0.1.1# make 
mips-linux-gnu-gcc -static -c -I. -O -Wall globals.c 
mips-linux-gnu-gcc -static -c -I. -O -Wall view.c 
mips-linux-gnu-gcc -static -c -I. -O -Wall aliens.c 
mips-linux-gnu-gcc -static -c -I. -O -Wall ufo.c 
mips-linux-gnu-gcc -static -c -I. -O -Wall player.c 
mips-linux-gnu-gcc -static -c -I. -O -Wall nInvaders.c 
mips-linux-gnu-gcc -static -L /root/ncurses-5.9-20141101/lib -onInvaders globals.o view.o aliens.o ufo.o player.o nInvaders.o -lncurses 
[email protected]:~/ninvaders-0.1.1# ls -l nInvaders 
-rwxr-xr-x 1 root root 933003 Nov 6 16:18 nInvaders 
[email protected]:~/ninvaders-0.1.1# mv nInvaders nInvaders_IOSXE_MIPS 

對於未來的Google,Makefile文件是:

CC=mips-linux-gnu-gcc -static 
CFLAGS=-O -Wall 
LIBS=-lncurses 
LDFLAGS=-L /root/ncurses-5.9-20141101/lib 

CFILES=globals.c view.c aliens.c ufo.c player.c nInvaders.c 
HFILES=globals.h view.h aliens.h ufo.h player.h nInvaders.h 
OFILES=globals.o view.o aliens.o ufo.o player.o nInvaders.o 
all:   nInvaders 

nInvaders:  $(OFILES) $(HFILES) 
       $(CC) $(LDFLAGS) [email protected] $(OFILES) $(LIBS) 

.c.o: 
       $(CC) -c -I. $(CFLAGS) $(OPTIONS) $< 
clean: 
       rm -f nInvaders $(OFILES) 

最終結果:

[email protected]:~/ninvaders-0.1.1# file nInvaders_IOSXE_MIPS 
nInvaders_IOSXE_MIPS: ELF 32-bit MSB executable, MIPS, 
MIPS32 rel2 version 1, statically linked, for GNU/Linux 2.6.16, not stripped 

屏幕截圖:
http://imgur.com/a/kf8cu
https://www.youtube.com/watch?v=-qbmKYQ2jCA

相關問題