2014-10-04 62 views
3

我想在x86机器上使用gcc生成MIPS二进制文件。为了安装MIPS交叉编译器,我遵循this page的指示。我可以成功安装gcc和binutils。我试图用交叉编译器编译一个简单的hello世界程序。mrt交叉编译器中的crt1.o错误

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -mips1 hi.c 

我得到了以下错误。

/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory 
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crti.o: No such file or directory 
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find -lc 
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crtn.o: No such file or directory 
collect2: error: ld returned 1 exit status 

我在网上做了一些研究,找出问题所在,并将我用过的命令更改为以下内容。

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -B/usr/lib/i386-linux-gnu -mips1 hi.c 

现在我收到此错误信息:

/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: /usr/lib/i386-linux-gnu/crt1.o: Relocations in generic ELF (EM: 3) 
/usr/lib/i386-linux-gnu/crt1.o: error adding symbols: File in wrong format 
collect2: error: ld returned 1 exit status 

我不知道是什么问题。我能想到的唯一的事情是在构建gcc时传递给配置程序的“--without-headers”选项。在linux-mips页面上为gcc配置命令如下。

% ../gcc-3.8.2/configure --target=$TARGET --prefix=$PREFIX \ 
    --enable-languages=c --without-headers \ 
    --with-gnu-ld --with-gnu-as \ 
    --disable-shared --disable-threads \ 
    --disable-libmudflap --disable-libgomp \ 
    --disable-libssp --disable-libquadmath \ 
    --disable-libatomic 

我希望得到一些帮助。我生成交叉编译器的系统使用gcc4.7.2-5。我使用gcc-4.8.2和binutils-2.24的源代码来生成交叉编译器。

+0

如果您只是想为mips-linux进行交叉编译,您可能需要查看http://ellcc.org。二进制文件也可以下载。 – 2014-10-06 16:06:26

+0

您错过了运行时库。除了编译器和binutils之外,完整的开发环境还需要为MIPS构建库。 – 2014-10-07 15:41:34

回答

2

/选择/交叉/斌/ mipsel体系未知-Linux的GNU-GCC -mips1 hi.c

添加SYSROOT到编译命令。它应该类似于:

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -mips1 --sysroot=/opt/cross/... hi.c 

SYSROOT会自动提供的头文件和库路径(而不是增加-I-L单独)。

您将知道何时有SYSROOT,因为在所使用的路径中将会出现bin/include/lib/。例如,这里有一个SYSROOTarm-linux-gnueabi(即arm-linux-gnueabi-gccarm-linux-gnueabi-g++):

$ ls /usr/arm-linux-gnueabi 
bin include lib 

所以,在这个例子中,你可以使用--sysroot=/usr/arm-linux-gnueabi

如果您需要定位SYSROOT帮助,然后执行find

$ find /usr -name crt1.o 
/usr/arm-linux-gnueabi/lib/crt1.o 
/usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o 
/usr/lib/x86_64-linux-gnu/crt1.o 

在你的情况,你可能会从/opt/cross搜索。显然,你会想要一个目标(arm-linux-gnueabi),而不是主机的(x86_64-linux-gnu)。

+0

当我使用sysroot选项时,出现以下错误。 '/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld:这个链接器是未配置为使用sysroots' 我想我必须使用sysroot选项重新编译整个东西。 – puck 2014-10-06 00:47:30

+0

对不起,我从来没有见过。但我不建立我自己的工具链。 – jww 2014-10-06 01:31:26

0

添加--sysroot =可以解决此问题。 由于你正在交叉编译,你不应该只选择任何其他文件夹,其中crt1.o或crtX.o作为你的sysroot目录。它可能是你的主机的文件。 (如果你正在x86上运行,它将用于x86)。它再次从32位和64位不等。

使用较新版本的GCC工具链,您需要有一个sdk部分,它有相应的sysroot和crt1.o.这应该与你的ABI和你的目标架构一致。