gcc - 基于 MIPS 的 codesourcery 工具链的编译参数?

标签 gcc compilation mips embedded-linux gnu-toolchain

我在我的 WIN 7 机器上安装了用于 mips32 架构的 codesourcery 交叉编译工具链。我想首先为我的路由器编译一个基于 MIPS32 的简单“阶乘”二进制文件。在网上查了一下,发现它是基于MIPS32 big-endian的。

#cat /proc/cpuinfo
system type             : 96338W2
processor               : 0
cpu model               : BCM6338 V1.0
BogoMIPS                : 239.20
wait instruction        : no
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : no
unaligned access        : 1269919
VCED exceptions         : not available
VCEI exceptions         : not available

# cat /proc/version
Linux version 2.6.8.1 (root@WangHaiTao) (gcc version 3.4.2) #1 Wed Sep 2 10:13:53 CST 2009

路由器的 LIB 目录包含:

ld-uClibc.so.0 libc.so.0 libcrypt.so.0 libcrypto.so.0.9.7 libdl.so.0 libm.so.0 libnvram.so libpsi.so libpsixml.so libresolv.so.0 libssl.so.0.9.7 libutil.so.0 libwlbcmcrypto.so libwlbcmshared.so libwlctl.so modules

工具链信息:(在主机WIN 7系统上)

C:\code>mips-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=mips-linux-gnu-gcc
COLLECT_LTO_WRAPPER=f:/program files/codesourcery/sourcery_codebench_lite_for_mi
ps_gnu_linux/bin/../libexec/gcc/mips-linux-gnu/4.6.3/lto-wrapper.exe
Target: mips-linux-gnu
Configured with: /scratch/cmoore/2012.03-63-linux-lite/src/gcc-4.6-2012.03/confi
gure --build=i686-pc-linux-gnu --host=i686-mingw32 --target=mips-linux-gnu --ena
ble-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with
-arch-32=mips32r2 --with-arch-64=mips64r2 --with-float=hard --with-mips-plt --en
able-extra-sgxxlite-multilibs --with-gnu-as --with-gnu-ld --with-specs='%{save-t
emps: -fverbose-asm} -D__CS_SOURCERYGXX_MAJ__=2012 -D__CS_SOURCERYGXX_MIN__=3 -D
__CS_SOURCERYGXX_REV__=63 %{O2:%{!fno-remove-local-statics: -fremove-local-stati
cs}} %{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 2012.03-63' --wi
th-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=
/opt/codesourcery --with-sysroot=/opt/codesourcery/mips-linux-gnu/libc --with-bu
ild-sysroot=/scratch/cmoore/2012.03-63-linux-lite/install/host-i686-mingw32/mips
-linux-gnu/libc --with-libiconv-prefix=/scratch/cmoore/2012.03-63-linux-lite/obj
/host-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr --with-gmp=/scratch/cmoore
/2012.03-63-linux-lite/obj/host-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr
--with-mpfr=/scratch/cmoore/2012.03-63-linux-lite/obj/host-libs-2012.03-63-mips-
linux-gnu-i686-mingw32/usr --with-mpc=/scratch/cmoore/2012.03-63-linux-lite/obj/
host-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr --with-ppl=/scratch/cmoore/
2012.03-63-linux-lite/obj/host-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr -
-with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with
-cloog=/scratch/cmoore/2012.03-63-linux-lite/obj/host-libs-2012.03-63-mips-linux
-gnu-i686-mingw32/usr --with-libelf=/scratch/cmoore/2012.03-63-linux-lite/obj/ho
st-libs-2012.03-63-mips-linux-gnu-i686-mingw32/usr --disable-libgomp --enable-po
ison-system-directories --with-build-time-tools=/scratch/cmoore/2012.03-63-linux
-lite/obj/tools-i686-pc-linux-gnu-2012.03-63-mips-linux-gnu-i686-mingw32/mips-li
nux-gnu/bin --with-build-time-tools=/scratch/cmoore/2012.03-63-linux-lite/obj/to
ols-i686-pc-linux-gnu-2012.03-63-mips-linux-gnu-i686-mingw32/mips-linux-gnu/bin
Thread model: posix
gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-63)



我尝试了以下编译参数:

  1. mips-linux-gnu-gcc -mips32 -muclibc -o 阶乘阶乘.c

当我在 MIPS 机器上运行输出二进制文件时,它只是打印“无法加载库 'libgcc_s.so.1'”。

  1. mips-linux-gnu-gcc -muclibc -mips32 -static-libgcc -s -o 阶乘阶乘.c

当我运行其输出时,它会打印“sigsegv”。

这里出了什么问题?我应该输入什么编译器参数?请帮助我。

最佳答案

文件系统上有 libgcc_s.so.1 吗?如果没有,工具链将有一个文件夹复制到文件系统上。去做。

如果这样做,请确保 LD_LIBRARY_PATH 设置正确。

编辑:一般问题解决

当您创建可执行文件时,您将链接到库。这些库还必须存在于运行可执行文件的环境中。因此,一般来说,在嵌入式系统中,三件事必须匹配

  1. 内核头
  2. 工具链
  3. 文件系统

这是它们之间的关系

您的内核头文件最终以某种形式用作程序中的#include。因此,工具链使用的 header 必须与实际运行的 header 匹配,并且将出现在文件系统中。

工具链将包含要链接的库,以便可以创建可执行文件[想想 libc 和其他]。这些必须与您的运行时环境(即您的文件系统)中存在的相同

工具链必须创建适合您的内核的格式。可执行格式。

因此,一般来说,如果您的文件系统中没有文件,而尝试执行它时,它应该来自某个 sdk 或您的工具链。 如果文件系统中有它,那么您可以指示您的工具链从那里使用它。

如果由于某种原因文件系统中没有库,解决该问题的一种方法是构建静态可执行文件。但您必须确保您知道自己在做什么。

编辑:您面临的具体问题 如果你的文件系统是只读的,那么要么你已经拥有了所有的东西,并且提供了一个 sdk 来进行开发。如果您没有,您仍然可以通过让工具链使用文件系统中的库来进行开发[想想-I,-L]。

编辑2: 您的文件系统似乎是 ucLibc 的。您的工具链似乎是针对 libc 构建的。这里面有你不匹配的地方。

现在您似乎有一个只读文件系统,没有开发 SDK。所以我不确定以下内容是否有效。 您的工具链必须配置为仅使用文件系统中的文件并针对 ucLibc 配置。如果路由器人员已确保开发所需的所有文件在规则系统中可用,那就足够了。否则你需要他们的sdk。请参阅上面的编辑以获取解释。

关于gcc - 基于 MIPS 的 codesourcery 工具链的编译参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12183433/

相关文章:

c++ - std::vector : 无法将 'std::ostream {aka std::basic_ostream<char>}' 左值绑定(bind)到 'std::basic_ostream<char>&&'

c++ - 在 Mac 上编译 C++ 代码

css - 如何将 css 文件和 xml 文件与 GTK3 元素组合

assembly - MIPS - assembly BEQ 命令

C 中的调用堆栈回溯

c++ - 枚举类型比较错误

找不到路径中的 CMake 编译器

compilation - Raspberry Pi : undefined references to COMXImage and g_OMXImage上的XBMC 13.2链接器错误

c - mips 汇编中的嵌套循环

c++ - 关于 GDB 和 CRC 不匹配