您好,登錄后才能下訂單哦!
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 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 <stdio.h>
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 <stdio.h>
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。