Cross compiling for MIPS router from x86

Check out:

http://www.kegel.com/crosstool/

It's the authoritative site on cross-compiling under GCC.


You are right, you need a proper mips toolchain to cross-compile your application and Buildroot can do that. But you may need to tweak buildroot's menuconfig options. Depending on the output of file, your options may change. On my system, binary apps inform the following:

ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV)

These are the options I have enabled for my Buildroot's menuconfig:

Target Architecture (mips)  ---> 
Target Architecture Variant (mips 32r2)  --->                                                            
Target ABI (o32)  --->                                                                                   
Target options  --->                                                                                     
Build options  --->   
    (/opt/cross-mips-buildroot) Toolchain and header file location?                                                                                   
Toolchain  --->        
    Toolchain type (Buildroot toolchain)  ---> 
    Kernel Headers (Linux 2.6.34.x kernel headers)  --->
    uClibc C library Version (uClibc 0.9.31.x)  ---> 
    [*] Build/install a shared libgcc?
    [*] Enable compiler tls support       
    [*] Build gdb debugger for the Target
    [*] Build gdb server for the Target
    [*] Build gdb for the Host
        GDB debugger Version (gdb 6.8)  --->
    [*] Enable large file (files > 2 GB) support?
    [*] Enable WCHAR support
    [*] Use software floating point by default
    [*] Enable stack protection support
    [*] Build/install c++ compiler and libstdc++?
    [*] Include target utils in cross toolchain  
Package Selection for the target  --->   
    [*] BusyBox
    [*]   Run BusyBox's own full installation
    Libraries  ---> 
        Networking  ---> 
            [*] libcurl
        Text and terminal handling  ---> 
            [*] icu
            -*- ncurses    
Target filesystem options  --->                                                                          
Bootloaders  --->                                                                                        
Kernel  --->

The toolchain itself is installed at /opt/cross-mips-buildroot. You can find the compiler and other tools on /opt/cross-mips-buildroot/usr/bin/

Try to compile a simple hello world application and see if you can run it inside the mips system.

Note: this configuration will not build a C++ compiler. If you need it, you can grep LIBSTDCPP .config and check if it's enable or not and change it to your likes. Then make menuconfig to make it happen.