【问题标题】:cross compile sh script to bin for enigma2 (mips) OpenEmbedded交叉编译 sh 脚本到 bin for enigma2 (mips) OpenEmbedded
【发布时间】:2013-10-10 08:50:41
【问题描述】:

我有一个使用 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 "("

很明显我忘记了交叉编译命令中的某些内容,但是什么?

【问题讨论】:

    标签: cross-compiling sh mips32 codesourcery enigma2


    【解决方案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 命令对您生成的二进制文件的输出是什么?

    【讨论】:

    • 感谢里卡多的回复。非常感谢您的帮助。当我比较你写的和我做的时,它似乎是一样的。所以一切都一定没问题。您要求输出二进制文件命令。你的意思是和你在'cat hello.c'的回复中写的一样的输出吗?如果是这样,那将是一个非常大的输出,因为我有一个很长的 shell 脚本。而且那个 shell 脚本本身没问题,因为当我不交叉编译它而只是用 gcc 为我的 Ubuntu 机器编译它时,它运行得很好。
    • 你好你好。我的意思是file 命令,在Ubuntu 系统上通常位于/usr/bin/file,如上面引用的输出中倒数第二行所示。你可以看到file 告诉我我生成的hello 文件是MIPS Linux 系统的32 位可执行文件。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2011-07-14
      • 2019-01-18
      • 2011-04-17
      • 2018-05-31
      • 2017-08-29
      • 2019-09-27
      • 1970-01-01
      • 1970-01-01
      • 2011-06-12
      相关资源
      最近更新 更多