大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

Secondtoolchain

2.2.3 preparation
1) create new user vita
groupadd vita
useradd -m -s /bin/bash -g vita vita
2) add file vita to /etc/sudoers.d, file content is below:
vita ALL=(ALL) NOPASSWD: ALL

埇桥区网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站设计等网站项目制作,到程序开发,运营维护。成都创新互联公司于2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司

3) mkdir /vita

4) mkdir source build cross-tool cross-gcc-tmp sysroot

5) chown -R vita.vita /vita

6) add below content to /home/vita/.bashrc

unset LANG
export HOST=i686-pc-linux-gnu
export BUILD=$HOST
export TARGET=i686-none-linux-gnu
export CROSS_TOOL=/vita/cross-tool
export CROSS_GCC_TMP=/vita/cross-gcc-tmp
export SYSROOT=/vita/sysroot
PATH=$CROSS_TOOL/bin:$CROSS_GCC_TMP/bin:/sbin:/usr/sbin:$PATH

7) su - vita

2.2.4 install binutils

1) tar xvf ../source/binutils-2.23.1.tar.bz2

2) mkdir binutils-build

3) cd binutils-build

4) ../binutils-2.23.1/configure --prefix=$CROSS_TOOL --target=$TARGET --with-sysroot=$SYSROOT

5) make

6) make install

2.2.5 compile freestanding cross tool

1) cd /vita/build

2)  tar xvf ../source/gcc-4.7.2.tar.bz2
       cd gcc-4.7.2/
       tar xvf ../../source/gmp-5.0.5.tar.bz2
       mv gmp-5.0.5/ gmp
       tar xvf ../../source/mpc-1.0.1.tar.gz
       mv mpc-1.0.1/ mpc
       tar xvf ../../source/mpfr-3.1.1.tar.bz2
       mv mpfr-3.1.1/ mpfr

       cd /vita/build

       mkdir gcc-build

       cd gcc-build

       ../gcc-4.7.2/configure --prefix=$CROSS_GCC_TMP --target=$TARGET --with-sysroot=$SYSROOT --with-newlib --enable-languages=c --with-mpfr-include=/vita/build/gcc-4.7.2/mpfr/src --with-mpfr-lib=/vita/build/gcc-build/mpfr/src/.libs --disable-shared --disable-threads --disable-decimal-float --disable-libquadmath --disable-libmudflap --disable-libgomp --disable-nls --disable-libssp

             make

             make install

             cd /vita/cross-gcc-tmp

             ln -s libgcc.a lib/gcc/i686-none-linux-gnu/4.7.2/libgcc_eh.a

2.2.6 install kernel header file

cd /vita/build

tar xvf ../source/linux-3.7.4.tar.xz 

cd linux-3.7.4/

make mrproper

make ARCH=i386 headers_check

make ARCH=i386 INSTALL_HDR_PATH=$SYSROOT/usr/ headers_install

2.2.7 compile object system C library

apt-get install gawk

cd /vita/build

tar xvf ../source/glibc-2.15.tar.xz

cd glibc-2.15

patch -p1 < ../../source/glibc-2.15-cpuid.patch

patch -p1 < ../../source/glibc-2.15-s_frexp.patch

mkdir glibc-build

cd glibc-build

../glibc-2.15/configure --prefix=/usr --host=$TARGET --enable-kernel=3.7.4 --enable-add-ons --with-headers=$SYSROOT/usr/include libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes libc_cv_ctors_header=yes

make

make install_root=$SYSROOT install

2.2.8 setup whole cross compiler

cd /vita/build/gcc-build

rm -rf *

../gcc-4.7.2/configure --prefix=$CROSS_TOOL --target=$TARGET --with-sysroot=$SYSROOT --with-mpfr-include=/vita/build/gcc-4.7.2/mpfr/src --with-mpfr-lib=/vita/build/gcc-build/mpfr/src/.libs --enable-languages=c,c++ --enable-threads=posix

make

make install

2.2.9 set the environment variable

1)add below content to /home/vita/.bashrc

export CC="$TARGET-gcc" 

export CXX="$TARGET-g++" 

export AR="$TARGET-ar" 

export AS="$TARGET-as" 

export RANLIB="$TARGET-ranlib" 

export LD="$TARGET-ld" 

export STRIP="$TARGET-strip"

export DESTDIR=$SYSROOT

2) source /home/vita/.bashrc

2.2.10 encapsulate cross pkg-config

1)add below content to .bashrc

unset PKG_CONFIG_PATH  

export PKG_CONFIG_LIBDIR=$SYSROOT/usr/lib/pkgconfig:\  

    $SYSROOT/usr/share/pkgconfig 

2)add file /vita/cross-tool/bin/pkg-config

  1. #!/bin/bash  

  2. HOST_PKG_CFG=/usr/bin/pkg-config  

  3.  

  4. if [ ! $SYSROOT ]; then  

  5.     echo "Please make sure you are in cross-compile environment!"  

  6.     exit 1  

  7. fi  

  8.  

  9. $HOST_PKG_CFG --exists $*  

  10. if [ $? -ne 0 ]; then  

  11.     exit 1  

  12. fi  

  13.  

  14. if $HOST_PKG_CFG $* | sed -e "s/-I/-I\/vita\/sysroot/g;\  

  15. s/-L/-L\/vita\/sysroot/g"  

  16. then  

  17.     exit 0  

  18. else  

  19.     exit 1  

  20. fi 

3) chmod a+x /vita/cross-tool/bin/pkg-config

2.2.11 handle libtool

find $SYSROOT -name "*.la" -exec rm -f '{}' \;

2.2.12 start code

foo.c

#include

void myinit(int argc, char **argv, char **envp)

{

        printf("%s\n",__FUNCTION__);

}

__attribute__((section(".init_array"))) typeof(myinit) *_myinit = myinit;

void test()

{

        printf("%s\n",__FUNCTION__);

}

bar.c

#include

void main()

{

        printf("Enter main.\n");

        test();

}

#  gcc -shared -fPIC foo.c -o libfoo.so

#  gcc bar.c -o bar -L./ -lfoo

#  LD_LIBRARY_PATH=./ ./bar

myinit

Enter main.

test


当前文章:Secondtoolchain
文章地址:http://dzwzjz.com/article/jjejcp.html
在线咨询
服务热线
服务热线:028-86922220
TOP