Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Second toolchain

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

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

#! / bin/bash

HOST_PKG_CFG=/usr/bin/pkg-config

If [! $SYSROOT]; then

Echo "Please make sure you are in cross-compile environment!"

Exit 1

Fi

$HOST_PKG_CFG-- exists $*

If [$?-ne 0]; then

Exit 1

Fi

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

S/-L/-L\ / vita\ / sysroot/g "

Then

Exit 0

Else

Exit 1

Fi

3) chmod aquix / 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.L /-lfoo

# LD_LIBRARY_PATH=./. / bar

Myinit

Enter main.

Test

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report