我有一个dreambox卫星接收器,它使用Enigma2 OpenEmbedded操作。所以MIPS架构。 我想在我的Ubuntu PC上将.sh文件交叉编译为Enigma2二进制文件。
我在我的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 "("
所以显然我在cross compile命令中忘记了什么,但是什么?
答案 0 :(得分:1)
(免责声明:我为CodeSourcery / Mentor Graphics工作。)
使用相同工具链的稍微更新版本,以下是从Ubuntu 12.04主机系统运行时的结果。首先,版本:
lite@sourcerydemo:~$ /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)
然后编码,构建和输出file命令以显示有关所生成的可执行文件的更多信息:
lite@sourcerydemo:~$ /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.
lite@sourcerydemo:~$ cat hello.c
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("hello world!\n");
}
lite@sourcerydemo:~$ /home/lite/CodeSourcery/Sourcery_CodeBench_Lite_for_MIPS_GNU_Linux/bin/mips-linux-gnu-gcc -mips32 hello.c -o hello
lite@sourcerydemo:~$ 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
您生成的二进制文件上的file命令输出是什么?
答案 1 :(得分:1)
您无需将Shell脚本编译为C即可运行它。只需将原始脚本复制到您的接收器并直接运行即可。