1

I would like to cross compile a simple program that uses libncurses on my x86_64. Target system is MIPS.

My crosstool-ng-1.20 build went fine (with sample mips-unknown-elf)

However, a simple hello world ends badly.

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

I'm clearly doing something terribly wrong here, but where do i start?


[Edit]

Thank you markgz. Codesourcery is exactly what i needed.

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

Proof of concept complete. Now off to compile my ncurses program.

[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.
4

2 回答 2

1

您可能需要构建 mips-linux-elf-gcc。您确定您的 MIPS 目标系统配置为大端序吗?

无论如何,您可以通过从这里下载免费的 Mentor/Codesourcery MIPS gnu/gcc 交叉编译工具链来避免所有这些问题。此工具链适用于 Windows 和 Linux。

于 2014-11-06T18:40:50.283 回答
0
root@x86host:~/ncurses-5.9-20141101# export CC=mips-linux-gnu-gcc
root@x86host:~/ncurses-5.9-20141101# ./configure --target=mips-linux-gnu --host=mips-linux-gnu
[..]
root@x86host:~/ncurses-5.9-20141101# make

然后,我从 /usr/include/ 复制了一些标题以使它们消失:

root@x86host:~/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


root@x86host:~/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
root@x86host:~/ninvaders-0.1.1# ls -l nInvaders
-rwxr-xr-x 1 root root 933003 Nov  6 16:18 nInvaders
root@x86host:~/ninvaders-0.1.1# mv nInvaders nInvaders_IOSXE_MIPS

对于未来的谷歌人,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) -o$@ $(OFILES) $(LIBS)

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

最终结果:

root@x86host:~/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

于 2014-11-06T21:43:03.520 回答