2014-10-04 117 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和你的目標架構一致。