1

我有一个使用 Enigma2 OpenEmbedded 运行的 Dreambox 卫星接收器。所以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 "("

所以很明显我在交叉编译命令中忘记了一些东西,但是什么?

4

2 回答 2

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)

然后编码、构建和文件命令的输出,以显示有关生成的可执行文件的更多信息:

 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 命令的输出是什么?

于 2013-10-10T18:59:19.210 回答
1

您无需将 shell 脚本编译为 C 即可运行它。只需将原始脚本复制到您的接收器并直接运行即可。

于 2020-11-05T11:34:10.467 回答