2013-10-10 47 views
1

我有一個Dreambox衛星接收器與Enigma2 OpenEmbedded操作。所以MIPS架構。 我想在我的Ubuntu PC上將一個.sh文件交叉編譯成一個Enigma2二進制文件。交叉編譯sh腳本以bin爲enigma2(mips)OpenEmbedded

我在Ubuntu PC上安裝了用於mips32體系結構的codesourcery交叉編譯工具鏈。

工具鏈信息:

/mips-compiler/mips-linux-gnu-gcc -v 

Using built-in specs. 
COLLECT_GCC=/mips-compiler/mips-linux-gnu-gcc 
COLLECT_LTO_WRAPPER=/root/CodeSourcery/Sourcery_CodeBench_Lite_for_MIPS_GNU_Linux/bin/../libexec/gcc/mips-linux-gnu/4.7.3/lto-wrapper 
Target: mips-linux-gnu 
Configured with: /scratch/cmoore/2013.05-36-mips-linux-lite/src/gcc-4.7-2013.05/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=mips-linux-gnu --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-arch-32=mips32r2 --with-arch-64=mips64r2 --with-float=hard --with-mips-plt --enable-extra-sgxxlite-multilibs --with-gnu-as --with-gnu-ld --with-specs='%{save-temps: -fverbose-asm} -D__CS_SOURCERYGXX_MAJ__=2013 -D__CS_SOURCERYGXX_MIN__=5 -D__CS_SOURCERYGXX_REV__=36 %{O2:%{!fno-remove-local-statics: -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}' --enable-languages=c,c++ --enable-shared --enable-lto --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery CodeBench Lite 2013.05-36' --with-bugurl=https://sourcery.mentor.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/mips-linux-gnu/libc --with-build-sysroot=/scratch/cmoore/2013.05-36-mips-linux-lite/install/mips-linux-gnu/libc --with-gmp=/scratch/cmoore/2013.05-36-mips-linux-lite/obj/pkg-2013.05-36-mips-linux-gnu/mips-2013.05-36-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-mpfr=/scratch/cmoore/2013.05-36-mips-linux-lite/obj/pkg-2013.05-36-mips-linux-gnu/mips-2013.05-36-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-mpc=/scratch/cmoore/2013.05-36-mips-linux-lite/obj/pkg-2013.05-36-mips-linux-gnu/mips-2013.05-36-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-ppl=/scratch/cmoore/2013.05-36-mips-linux-lite/obj/pkg-2013.05-36-mips-linux-gnu/mips-2013.05-36-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-cloog=/scratch/cmoore/2013.05-36-mips-linux-lite/obj/pkg-2013.05-36-mips-linux-gnu/mips-2013.05-36-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-libelf=/scratch/cmoore/2013.05-36-mips-linux-lite/obj/pkg-2013.05-36-mips-linux-gnu/mips-2013.05-36-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --disable-libgomp --disable-libitm --enable-poison-system-directories --with-build-time-tools=/scratch/cmoore/2013.05-36-mips-linux-lite/install/mips-linux-gnu/bin --with-build-time-tools=/scratch/cmoore/2013.05-36-mips-linux-lite/install/mips-linux-gnu/bin 
Thread model: posix 
gcc version 4.7.3 (Sourcery CodeBench Lite 2013.05-36) 

我用SHC到sh文件轉換爲.c文件 然後我交叉編譯的C文件到MIPS二進制使用命令:

/mips-compiler/mips-linux-gnu-gcc -mips32 -o test.bin test.sh.x.c 

沒有錯誤(我很高興,但不幸(見下文))。 然後複製bin文件到我的enigma2箱,並試圖執行它...

當我運行在MIPS機器我看到這​​個輸出二進制:

./test.bin: line 1: syntax error: unexpected "(" 

所以很明顯,我忘了東西在交叉編譯命令,但是什麼?

回答

1

(聲明:我CodeSourcery的/ Mentor Graphics公司工作。)

使用相同的工具鏈的一個稍微更新的版本,這裏是我的成績從一個Ubuntu 12.04主機系統中運行時。首先,該版本:

[email protected]:~$ /home/lite/CodeSourcery/Sourcery_CodeBench_Lite_for_MIPS_GNU_Linux/bin/mips-linux-gnu-gcc -v 
Using built-in specs. 
COLLECT_GCC=/home/lite/CodeSourcery/Sourcery_CodeBench_Lite_for_MIPS_GNU_Linux/bin/mips-linux-gnu-gcc 
COLLECT_LTO_WRAPPER=/home/lite/CodeSourcery/Sourcery_CodeBench_Lite_for_MIPS_GNU_Linux/bin/../libexec/gcc/mips-linux-gnu/4.7.3/lto-wrapper 
Target: mips-linux-gnu 
Configured with: /scratch/cmoore/2013.05-mips-linux/src/gcc-4.7-2013.05/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=mips-linux-gnu --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-arch-32=mips32r2 --with-arch-64=mips64r2 --with-float=hard --with-mips-plt --enable-extra-sgxxlite-multilibs --with-gnu-as --with-gnu-ld --with-specs='%{save-temps: -fverbose-asm} -D__CS_SOURCERYGXX_MAJ__=2013 -D__CS_SOURCERYGXX_MIN__=5 -D__CS_SOURCERYGXX_REV__=66 %{O2:%{!fno-remove-local-statics: -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}' --enable-languages=c,c++ --enable-shared --enable-lto --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery CodeBench Lite 2013.05-66' --with-bugurl=https://sourcery.mentor.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/mips-linux-gnu/libc --with-build-sysroot=/scratch/cmoore/2013.05-mips-linux/install/mips-linux-gnu/libc --with-gmp=/scratch/cmoore/2013.05-mips-linux/obj/pkg-2013.05-66-mips-linux-gnu/mips-2013.05-66-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-mpfr=/scratch/cmoore/2013.05-mips-linux/obj/pkg-2013.05-66-mips-linux-gnu/mips-2013.05-66-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-mpc=/scratch/cmoore/2013.05-mips-linux/obj/pkg-2013.05-66-mips-linux-gnu/mips-2013.05-66-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-ppl=/scratch/cmoore/2013.05-mips-linux/obj/pkg-2013.05-66-mips-linux-gnu/mips-2013.05-66-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-cloog=/scratch/cmoore/2013.05-mips-linux/obj/pkg-2013.05-66-mips-linux-gnu/mips-2013.05-66-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --with-libelf=/scratch/cmoore/2013.05-mips-linux/obj/pkg-2013.05-66-mips-linux-gnu/mips-2013.05-66-mips-linux-gnu.extras/host-libs-i686-pc-linux-gnu/usr --enable-libgomp --disable-libitm --enable-poison-system-directories --with-build-time-tools=/scratch/cmoore/2013.05-mips-linux/install/mips-linux-gnu/bin --with-build-time-tools=/scratch/cmoore/2013.05-mips-linux/install/mips-linux-gnu/bin SED=sed 
Thread model: posix 
gcc version 4.7.3 (Sourcery CodeBench Lite 2013.05-66) 

然後代碼,構建和文件命令的輸出顯示有關生成的可執行更多的信息:

[email protected]:~$ /home/lite/CodeSourcery/Sourcery_CodeBench_Lite_for_MIPS_GNU_Linux/bin/mips-linux-gnu-gcc --version 
mips-linux-gnu-gcc (Sourcery CodeBench Lite 2013.05-66) 4.7.3 
Copyright (C) 2012 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

[email protected]:~$ cat hello.c 
#include <stdio.h> 

int main(int argc, char *argv[]) { 
    printf("hello world!\n"); 
} 
[email protected]:~$ /home/lite/CodeSourcery/Sourcery_CodeBench_Lite_for_MIPS_GNU_Linux/bin/mips-linux-gnu-gcc -mips32 hello.c -o hello 
[email protected]:~$ file hello 
hello: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), for GNU/Linux 2.6.16, with unknown capability 0x41000000 = 0xf676e75, with unknown capability 0x10000 = 0x70401, not stripped 

什麼是文件命令對二進制輸出你生產?

+0

感謝里卡多的回覆。非常感謝你的幫助。 當我比較你寫的和我所做的時,它似乎是一樣的。這樣一切都會好的。 您詢問了二進制文件命令的輸出。你的意思是和你在'cat hello.c'回覆中寫的一樣嗎?如果是這樣,那將是一個非常大的輸出因爲我有一個長的shell腳本。而且這個shell腳本本身就沒問題,因爲當我不交叉編譯它時,只是用我的Ubuntu機器上的gcc編譯它時,它運行得非常完美。 –

+0

你好ni_hao。我的意思是'file'命令,通常位於Ubuntu系統的'/ usr/bin/file'中,如上面引用輸出的倒數第二行所示。您可以看到'file'告訴我,我生成的'hello'文件是MIPS Linux系統的32位可執行文件。 –