Compile parameters for MIPS based toolchain?

I have installed the toolwcery cross compile toolchain for mips32 architecture on my WIN 7 machince. I want to first compile a simple "factorial" binary for my router which is MIPS32 based. From a little internet search, I found it is based on 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 (root@WangHaiTao) (gcc version 3.4.2) #1 Wed Sep 2 10:13:53 CST 2009


The router LIB directory contains: 0 modules

Toolchain Information: (on WIN 7 host system)

C:\code>mips-linux-gnu-gcc -v
Using built-in specs.
COLLECT_LTO_WRAPPER=f:/program files/codesourcery/sourcery_codebench_lite_for_mi
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= --disable-nls --prefix=
/opt/codesourcery --with-sysroot=/opt/codesourcery/mips-linux-gnu/libc --with-bu
-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
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
-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
nux-gnu/bin --with-build-time-tools=/scratch/cmoore/2012.03-63-linux-lite/obj/to
Thread model: posix
gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-63)


I tried the following compilation options:

  • mips-linux-gnu-gcc -mips32 -muclibc -o factorial factorial.c

When I ran the output binary in the MIPS box, it just printed "unable to load library".

  • mips-linux-gnu-gcc -muclibc -mips32 -static-libgcc -s -o factorial factorial.c

When I run its output, it prints 'sigsegv'.

What's wrong here? What compiler option should I enter? Please help me.


source to share

2 answers

Do you have on your filesystem? If not, the toolchain will have a folder to copy to the file system. Do it.

If you do, make sure LD_LIBRARY_PATH is set correctly.

EDIT: General solution to the problem

When you create the executable, you link to the libraries. These libraries must also be present in the environment where you run the executable. Hence, generally speaking, in an embedded system, 3 things must match

  • Kernel headers
  • Tool chain
  • File system

This is how they are connected

Kernel headers are used as #include in your program in some form. So the headers used in the toolchain must match the actual launch and will be present on the filesystem.

The toolchain will be composed of libraries to be referenced so that an executable file can be generated [think libc and others]. They should be the same in your runtime, which is your file system.

The toolchain should create a format suitable for your kernel. Executable format.

So, in general, if you don't have a file on your filesystem when you try to execute, it must come from some sdk or your toolchain. If you have it on the filesystem, you can tell your toolchain to use it there.

One way to get around the problem if you don't have libraries on your filesystem for some reason is to create static executables. But you have to make sure you know what you are doing.

EDIT: The specific problem you are facing If you are using a read-only filesystem, or you already have everything on it and the sdk is provided for development against. If you don't have this, you can still develop by getting your toolchain to use libraries from your filesystem [think -I, -L].

EDIT 2: Your filesystem seems to be ucLibc. Your toolchain seems to be built against libc. This is your discrepancy.

You now have a read-only filesystem with no sdk development. So I'm not sure if the following will work. Your toolchain should be configured to use only files from your filesystem and configured for ucLibc. If the guys from the router made sure that all the files needed for development are available in the rilesystem well enough. Otherwise you need their sdk. See above for an explanation.



I have successfully compiled this

#include <iostream>
using namespace std;

int main() {
  cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
  return 0;

mips-linux-gnu-g++ -muclibc -mips32  main.cpp -o main




All Articles