ubuntu16.04编译gcc5.04为X86-mips交叉编译器

/**************************************************************************************

 

       mips-elf的交叉编译环境源自网络中的一片文章,但我找不到了出处。同时也经过了我的

一些修改,最终我在slackware 12.0的Linux中成功的配置出了这个交叉编译环境。至于在

其他版本的linux中我相信也是应该可以成功编译的,不过我会尽快在其他的linux中进行

验证的,以方便大家参考。对于不足之处还请指正!!

 

**************************************************************************************/

 

The following is steps to build cross compilers. So far, I tried only for PowerPC and MIPS.

Basically, all you have to do is to follow the following 9 steps.

  1. Download sources
  2. Set environment variables
  3. Build binutils
  4. Build bootstrap gcc
  5. Build newlib
  6. Build gcc again with newlib
  7. GDB with PSIM
  8. Compile your code
  9. Run

1. What do you need?

First, you have to obtain the following source codes

2. Set environment variables

First, choose your taget such as powerpc-eabi, powerpc-elf, mips-elf, and so on

For bash simply type

% export TARGET=powerpc-eabi

% export PREFIX=/usr/local/$TARGET

% export PATH=$PATH:$PREFIX/bin

3. Build binutils

% tar xjfv binutils-2.17.tar.bz2

% mkdir build-binutils

% cd build-binutils

% ../binutils-2.17/configure --target=$TARGET --prefix=$PREFIX

% make all

% make install

4. Build bootstrap GCC

% tar xjfv gcc-4.1.1.tar.bz2

% mkdir build-gcc

% cd build-gcc

% ../gcc-4.1.1/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib --with-gnu-as --with-gnu-ld

% make all-gcc

% make install-gcc

--with-gnu-as --with-gnu-ld prevents native assembler on certain architectures. (for others, these do not have any effects)

5. Build newlib

Newlib provides standard C library for embedded systems

% tar xzfv newlib-1.14.0.tar.gz 

% mkdir build-newlib

% cd build-newlib

% ../newlib-1.14.0/configure --target=$TARGET --prefix=$PREFIX

% make all

% make install

6. Build GCC again with newlib

% cd build-gcc

% ../gcc-4.1.1/configure --target=$TARGET --prefix=$PREFIX --with-newlib --with-gnu-as --with-gnu-ld --disable-shared --disable-libssp

% make all

% make install

7. GDB with PSIM

% tar xjfv gdb-6.3.tar.bz2  

% mkdir build-gdb

% cd build-gdb

% ../gdb-6.3/configure --target=$TARGET --prefix=$PREFIX --enable-sim-powerpc

--enable-sim-stdio

% make all

% make install

Congratulations! You build your tool chain

8. Compile your code

Now, it's time to compile your code.

% powerpc-eabi-gcc -mcpu=405 hello.c -o hello -msim

% mips-elf-gcc -Tidt.ld -mips4 hello.c -o hello

-T option specifies libraries that include start code.

To Compile with specific Memory map

% powerpc-eabi-gcc -Wl,-Ttext,0x4000,-Tdata,0xf000 hello.c -msim

(-Wl,-Ttext,0x4000,-Tdata,0x10000)

9. Run

% powerpc-eabi-run hello

% mips-elf-run hello

猜你喜欢

转载自blog.csdn.net/renjiewen1995/article/details/53290548
今日推荐