linux 交叉编译经验总结

linux 交叉编译经验总结

前言

在linux -arm 平台下,尽量用yocto ,builidroot构建环境编译软件,这样会省去很多麻烦,但是有时避免不了的需要手动进行交叉编译。
所有觉得非常有必要对交叉编译进行一下总结。
备注:文中主要是对之前交叉编译的总结,部分细节因为时间久远,可能丢失。

不同平台下环境的区别

NXP 的平台(yocto)

NXP 的yocto生成的sdk,安装后会有一个脚本 environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 在交叉编译时一般需要先source environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 这个脚本。

注意在某些情况下交叉编译先source脚本会干扰编译的环境变量,环境变量冲突,导致交叉编译报错失败。本文会介绍如何解决这种问题。

脚本内容如下,会指定很多的变量

export SDKTARGETSYSROOT=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi
export PATH=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/x86_64-pokysdk-linux/usr/bin:/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:$PATH
export CCACHE_PATH=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/x86_64-pokysdk-linux/usr/bin:/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:$CCACHE_PATH
export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT
export PKG_CONFIG_PATH=$SDKTARGETSYSROOT/usr/lib/pkgconfig
export CONFIG_SITE=/opt/fsl-imx-x11/3.14.52-1.1.0/site-config-cortexa9hf-vfp-neon-poky-linux-gnueabi
export OECORE_NATIVE_SYSROOT="/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/x86_64-pokysdk-linux"
export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"
export OECORE_ACLOCAL_OPTS="-I /opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/x86_64-pokysdk-linux/usr/share/aclocal"
export PYTHONHOME=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/x86_64-pokysdk-linux/usr
export CC="arm-poky-linux-gnueabi-gcc  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CXX="arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CPP="arm-poky-linux-gnueabi-gcc -E  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export AS="arm-poky-linux-gnueabi-as "
export LD="arm-poky-linux-gnueabi-ld  --sysroot=$SDKTARGETSYSROOT"
export GDB=arm-poky-linux-gnueabi-gdb
export STRIP=arm-poky-linux-gnueabi-strip
export RANLIB=arm-poky-linux-gnueabi-ranlib
export OBJCOPY=arm-poky-linux-gnueabi-objcopy
export OBJDUMP=arm-poky-linux-gnueabi-objdump
export AR=arm-poky-linux-gnueabi-ar
export NM=arm-poky-linux-gnueabi-nm
export M4=m4
export TARGET_PREFIX=arm-poky-linux-gnueabi-
export CONFIGURE_FLAGS="--target=arm-poky-linux-gnueabi --host=arm-poky-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"
export CFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types"
export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types"
export LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed"
export CPPFLAGS=""
export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"
export OECORE_DISTRO_VERSION="3.14.52-1.1.0"
export OECORE_SDK_VERSION="3.14.52-1.1.0"
export ARCH=arm
export CROSS_COMPILE=arm-poky-linux-gnueabi-

# Append environment subscripts
if [ -d "$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do
	    source $envfile
    done
fi
if [ -d "$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do
	    source $envfile
    done
fi

Rockchip 瑞芯微平台(buildroot 这里主要针对1108)

rk的SDK一般先构建编译器,会先构建二个编译器,一个是编译内核用的,一个是构造文件系统的。1108使用构建文件系统的编译器路径如下

/home/xx/work/rv1108/prebuilts/toolschain/usr/arm-buildroot-linux-gnueabihf/bin

如果使用buildroot 构造文件系统,可以生成类似yocto的sdk (不提供完整的sdk,但提示交叉编译器与对应的库)。
在buildroot 目录下

make sdk   

** 上述make sdk 在rv1109官方提供的环境中可行,1108提供的方式有点不一样 **

交叉编译基础知识

编译中常用的变量

  1. CC 指定gcc
  2. CXX 指定g++
  3. CFLAGS 指定c语言头文件路径
  4. CPPFLAGS 指定c++ 头文件路径

注意: CFLAGS 与 CPPFLAGS 等号右边带双引号,同时还带有‘-I’ ,且I与表示路径的’/’ 没有空格

  • 应用举例如下,GDB的交叉编译
gdb 的交叉编译 
./configure --prefix=/home/xx/work/rv1108/all_out/gdb --host=arm-linux --disable-tui --with-termcap=no --with-curses=no --enable-shared  CFLAGS="-I/home/xx/work/rv1108/gs_out/include" LDFLAGS="-L/home/xx/work/rv1108/gs_out/lib" CC=arm-linux-gcc CXX=arm-linux-g++ --with-decnumber=no --without-python --disable-libtool

  1. PKG_CONFIG_PATH

PKG_CONFIG_PATH 很重要的一个设置功能,设置好后,效果相当于设置好指定的头文件和指定的库,效果与CFLAGS CPPFLAGS LDFLAGS 等相当。但是注意,有些库没有对应的pc 配置文件,无法指定PKG_CONFIG_PATH。

  • 如gstreamer的交叉编译
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/xx/work/rv1108/out/system/lib/pkgconfig:/home/xx/work/rv1108/ffmpeg_out/lib/pkgconfig:/home/xx/work/rv1108/gs_out/lib/pkgconfig:  

CC=arm-linux-gcc ./configure --build=i686-linux --host=arm-linux --prefix=/home/xx/work/rv1108/gs_out --disable-registry --disable-loadsave --disable-gtk-doc ac_cv_func_register_printf_function=no --disable-tests --disable-valgrind --disable-debug --disable-gst-debug --disable-examples --disable-benchmarks

  • pkgconfig 文件 一般在make install 安装目录的lib 下,如/lib/pkgconfig

下面为ffpeg_out/lib/pkconfig/libavcode.pc 内容

prefix=/home/xx/work/rv1108/ffmpeg_out
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include

Name: libavcodec
Description: FFmpeg codec library
Version: 57.34.100
Requires: 
Requires.private: libswresample >= 2.0.101, libavutil >= 55.20.100
Conflicts:
Libs: -L${libdir}  -lavcodec 
Libs.private: -liconv -lasound -lxvidcore -L/home/xx/work/rv1108/ffmpeg_out/lib -lx264 -lm -lz -pthread -ldl -lmpp -lvpu -ljpeg
Cflags: -I${includedir}
  • 如dbus的交叉编译
dbus
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/xx/work/rv1108/out/system/lib/pkgconfig:/home/xx/work/rv1108/ffmpeg_out/lib/pkgconfig:/home/xx/work/rv1108/gs_out/lib/pkgconfig   
 
./configure --prefix=/home/xx/work/rv1108/gs_out --host=arm-linux --with-x=no ac_cv_have_abstract_sockets=yes --enable-shared CC=arm-linux-gcc  LDFLAGS="-L/home/xx/work/rv1108/gs_out/lib" CPPFLAGS="-I/home/xx/work/rv1108/gs_out/include" \
EXPAT_CFLAGS=/home/xx/work/rv1108/gs_out/include EXPAT_LIBS="-L/home/xx/work/rv1108/gs_out/lib -lexpat" 

  1. LDFLAGS 设置库的路径,示例见前面的dbus的交叉编译

  2. C_INCLUDE_PATH 有时编译报错提示找不到对应的头文件时,设置包含头文件的路径。

  • C_INCLUDE_PATH 举例如下
libxml 的交叉编译,先设置C_INCLUDE_PATH
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/home/xx/work/rv1108/ffmpeg_out/include:/home/xx/work/rv1108/out/system/include:/home/xx/work/rv1108/gs_out/include:/home/xx/work/rv1108/gs_out/include/python2.7

  1. LD_LIBRARY_PATH

LD_LIBRARY_PATH 影响程序的运行,对编译没有影响。除非编译时中断的生成的可执行文件需要指定运行库的路径

  1. ARCH

这个设置也比较重要,一般在编译内核时用的较多 make ARCH=arm -j 16
在编译其它软件时指定–host=arm-linux 基本下可以不用再设置ARCH=arm。当然也可以设置ARCH=arm

  1. 其它影响编译的变量选项
    如下所示是dbus 的./configure -h 的部分内容
Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  CPP         C preprocessor
  LT_SYS_LIBRARY_PATH
              User-defined run-time library search path.
  CXXCPP      C++ preprocessor
  PKG_CONFIG  path to pkg-config utility
  GLIB_CFLAGS C compiler flags for GLIB, overriding pkg-config
  GLIB_LIBS   linker flags for GLIB, overriding pkg-config
  GIO_UNIX_CFLAGS
              C compiler flags for GIO_UNIX, overriding pkg-config
  GIO_UNIX_LIBS
              linker flags for GIO_UNIX, overriding pkg-config
  PYTHON      the Python interpreter
  EXPAT_CFLAGS
              C compiler flags for EXPAT, overriding pkg-config
  EXPAT_LIBS  linker flags for EXPAT, overriding pkg-config
  THREAD_LIBS
  SELINUX_CFLAGS
              C compiler flags for SELINUX, overriding pkg-config
  SELINUX_LIBS
              linker flags for SELINUX, overriding pkg-config
  APPARMOR_CFLAGS
              C compiler flags for APPARMOR, overriding pkg-config
  APPARMOR_LIBS
              linker flags for APPARMOR, overriding pkg-config
  APPARMOR_2_10_CFLAGS
              C compiler flags for APPARMOR_2_10, overriding pkg-config
  APPARMOR_2_10_LIBS
              linker flags for APPARMOR_2_10, overriding pkg-config
  SYSTEMD_CFLAGS
              C compiler flags for SYSTEMD, overriding pkg-config
  SYSTEMD_LIBS
              linker flags for SYSTEMD, overriding pkg-config
  VALGRIND_CFLAGS
              C compiler flags for VALGRIND, overriding pkg-config
  VALGRIND_LIBS
              linker flags for VALGRIND, overriding pkg-config
  XMKMF       Path to xmkmf, Makefile generator for X Window System

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations

PYTHON . EXPAT_CFLAGS 等变量,除了上面提到的9个变量通用外,其它的变量有些也基本通用,只是用的少(如PYTHON), 而有些可能是当前软件所特有的定义和依赖的变量。

常用的选项

  1. –prefix 指定安装路径,每次交叉编译几乎都用到

  2. –with-sysroot 这个也很重要,相关于告诉要交叉编译的环境,找相应的bin lib include 以哪个路径做为sysroot 去找。如果没有指定,可能默认找的是/usr/bin /usr/lib 等路径的。会导致编译报莫名奇妙的错误。

经验:
在编译gstreamer 时
设置 CPPFLAGS LDFAGS LIBS提示找不到对应的库,最后只能把库copy ~/work/rv1108/prebuilts/toolschain/usr/arm-buildroot-linux-gnueabihf/sysroot 才编译通过.
后面发现configure 中有一个–with-sysroot 选项。应该指定sysroot后就不用copy的动作了

  1. –host 如果是编译运行在arm端的软件 --host 设置如下
--host=arm-linux

与编译器名称无关,不管编译器bin 的名字是arm-linux-gcc 还是arm-buildroot-linux-gnueabihf-gcc,或者是arm-linux-gnueabihf-gcc host 都等于arm-linux

gcc-arm-linux-gnueabihf 与arm-linux-gnueabihf-gcc 区别:
gcc-arm-linux-gnueabihf : ubunt 下包的名字(apt-get install gcc-arm-linux-gnueabihf 包名)
arm-linux-gnueabihf-gcc : 二进度执行文件的名字。 arm-linux-gnueabihf-gcc -o test test.c

  1. –extra-ldflags --extra-libs 等特定软件才有的选项
  • 例如FFMPEG 视频编解码库的交叉编译
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/xx/work/rv1108/all_out/sys_out/lib
./configure --prefix=/home/xx/work/rv1108/ffmpeg_out --enable-shared --disable-static --enable-gpl --enable-cross-compile --arch=arm --disable-stripping --target-os=linux --enable-libx264 --enable-libxvid --cc=arm-linux-gcc --cxx=arm-linux-g++ --enable-swscale \
--extra-ldflags=-L/home/xx/work/rv1108/out/system/lib \
--extra-cflags=-I/home/xx/work/rv1108/out/system/include \
--extra-ldflags=-L/home/xx/work/rv1108/gs_out/lib \
--extra-cflags=-I/home/xx/work/rv1108/gs_out/include \
--extra-ldflags=-L/home/xx/work/rv1108/ffmpeg_out/lib \
--extra-cflags=-I/home/xx/work/rv1108/ffmpeg_out/include \
--extra-cflags=-I/home/xx/work/rv1108/ffmpeg_out/include/libdrm \
--extra-libs="-ldl -lmpp -lvpu -ljpeg" --enable-ffplay --enable-hardcoded-tables \
--extra-ldflags=-L/home/xx/work/rv1108/all_out/sys_out/lib --extra-cflags=-I/home/xx/work/rv1108/all_out/sys_out/include 
\
--enable-rkmpp --enable-version3 --enable-libdrm 
--sysroot=/home/xx/work/rv1108/prebuilts/toolschain/usr/arm-rkcvr-linux-uclibcgnueabihf/sysroot

其它的选项,可以通过./configure -h 查看,需要仔细查看./configure -h 的内容,有些选项隐藏的比较深(这里不好具体举例,因为太久了,忘记是哪个软件,总之当编译出现问题时./configure -h 要细读)。

** 注意: ** 交叉编译不要使用root 用户进行,以防不小心没设置好–prefix ,然后 make install 把arm的库安装到了/usr/bin 影响主机系统。

python 版本的问题

很多软件的编译依赖python,而python2 和python3又有很大的区别,无法完全兼容,所以有时需要在python 不同版本间的切换。

  1. 首先确保本机上安装不同的python 版本。
  2. 把想要的py版本增加进来,下面是把python3.5增加进来
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 3
  1. 切换想要的python 版本
sudo update-alternatives --config python

使用cmake的情况

主要设置 CMAKE_INSTALL_PREFIX

例如:交叉编译mpp
export CC=arm-linux-gcc
export CXX=arm-linux-g++
export CMAKE_INSTALL_PREFIX=/home/xx/work/rv1108/gs_out 此方法用cmake时无用
在cmake_install.cmake中设置
SET(CMAKE_INSTALL_PREFIX /home/xx/work/rv1108/gs_out)

变量的冲突问题

在NXP提供的sdk 交叉编译环境下。先source environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 环境,但有些软件这样交叉编译时会报错(具体哪个软件忘记了),当时发现如果不source environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 而是单独的设备 CC 、CXX、ARCH、等前面提到的变量,交叉编译时可以成功。后面发现是因为source environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 环境变量设置导致的问题。

当知道是哪个环境变量影响编译时,也可以先source source environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
然后unset 删除变量

sysroot 的指定

sysroot 设置很重要,所以单独做一个章节,有些sdk包指定了 --host=arm-linux 后会自动查找gcc,g++等,同时会指定sysroot(不用特意指定),而有些需要自己设置,或者指定–with-sysroot。
NXP 提供的编译器中,source对应的环境变量后,会设置

export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT
export CC="arm-poky-linux-gnueabi-gcc  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CXX="arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"

注意查看 --sysroot 在CC 和CXX 编译器中就指定了。指定了编译链接的库为sysroot路径下的库。

关于sysroot 见下面的 “qt应用的交叉编译”,和 “交叉编译举例”

隐藏的选项

见“交叉编译举例”

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-pic[=PKGS]       try to use only PIC/non-PIC objects [default=use
                          both]
  --with-aix-soname=aix|svr4|both
                          shared library versioning (aka "SONAME") variant to
                          provide on AIX, [default=aix].
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-sysroot[=DIR]    Search for dependent libraries within DIR (or the
                          compiler's sysroot if not specified).
  --with-pkgversion=PKG   Add PKG to the version string
  --with-bugurl=URL       Direct users to URL to report a bug

中的–without-sysroot

  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)

这里的PACKAGE 指Optional Packages

常见源码的交叉编译

  • qt的交叉编译
./configure -prefix /home/liu/work/rv1108/liuyinggui/qt_out \
-confirm-license \
-opensource \
-shared \
-release  \
-make libs \
-optimized-qmake \
-pch \
-linuxfb \
-qt-libjpeg \
-qt-libpng \
-qt-zlib \
-no-opengl \
-no-sse2 \
-no-openssl \
-no-cups \
-no-dbus \
-no-xcb \
-no-separate-debug-info \
-nomake examples -nomake tests -no-iconv \
-xplatform linux-arm-gnueabi-g++ \
-device-option CROSS_COMPILE=/home/xx/work/rv1108/prebuilts/toolschain/usr/bin/arm-linux- \
-tslib \
-kms \
-I/home/xx/work/rv1108/all_out/gs_out/include \
-I/home/xx/work/rv1108/all_out/gs_out/include/libdrm \
-L/home/xx/work/rv1108/all_out/gs_out/lib \
-I/home/xx/work/rv1108/tslib_out/include \
-L/home/xx/work/rv1108/tslib_out/lib \
-recheck-all

关于qt的交叉编译第一部分先编译出本机能运行的qmake ,然后再是交叉编译,如果要交叉编译qwebkit 还需要设置依赖库,设置python 版本。这里仅仅简单的贴了配置。
另一篇关于qt应用的交叉编译文章

  • gstream ,ffmpeg 的交叉编译前面已经提到。

交叉编译举例

目标:交叉编译prelink 软件在NXP 平台下使用
下载prelink程序

wget http://git.yoctoproject.org/cgit/cgit.cgi/prelink-cross/snapshot/prelink-cross-20151030_cross.tar.gz

先source environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 脚本
开始交叉编译
首先查看源码中的README 文档。

In order to build this, you will need to regenerate the autotools
files: autoreconf -if

然后查看 ./configure -h 看有哪些配置

`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-silent-rules   less verbose build output (undo: "make V=1")
  --disable-silent-rules  verbose build output (undo: "make V=0")
  --enable-dependency-tracking
                          do not reject slow dependency extractors
  --disable-dependency-tracking
                          speeds up one-time build
  --enable-shared[=PKGS]  build shared libraries [default=yes]
  --enable-static[=PKGS]  build static libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --disable-64-bit        only support 32-bit ELF
  --disable-selinux       Disable selinux support in the prelinker
  --disable-largefile     omit support for large files

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-pic[=PKGS]       try to use only PIC/non-PIC objects [default=use
                          both]
  --with-aix-soname=aix|svr4|both
                          shared library versioning (aka "SONAME") variant to
                          provide on AIX, [default=aix].
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-sysroot[=DIR]    Search for dependent libraries within DIR (or the
                          compiler's sysroot if not specified).
  --with-pkgversion=PKG   Add PKG to the version string
  --with-bugurl=URL       Direct users to URL to report a bug

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  CPP         C preprocessor
  LT_SYS_LIBRARY_PATH
              User-defined run-time library search path.
  CXXCPP      C++ preprocessor

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
autoreconf -if
./configure --prefix=/home/xx/work/tool/prelink/output --without-sysroot --host=arm-linux

还需要加上 –without-sysroot 参数,使得我们编译出来的 prelink 工具可以在运行时指定 sysroot 路径

编译时报错

checking whether the arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi linker (arm-poky-linux-gnueabi-ld  --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi) supports shared libraries... yes
checking for arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi option to produce PIC... -fPIC -DPIC
checking if arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi PIC flag -fPIC -DPIC works... yes
checking if arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi static flag -static works... no
checking if arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi supports -c -o file.o... yes
checking if arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi supports -c -o file.o... (cached) yes
checking whether the arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi linker (arm-poky-linux-gnueabi-ld  --sysroot=/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking libelf.h usability... no
checking libelf.h presence... no
checking for libelf.h... no
configure: error: libelf.h not found

提示找不到libelf
把libelf的源码下载下来

./configure --prefix=/home/xx/work/tool/prelink/elflib_output --host=arm-linux
make -j 16

到这时libelf 已经有了。
可以设置 LIBS(./configure -h 已经明确指明了可以)

./configure --prefix=/home/xx/work/tool/prelink/output --without-sysroot --host=arm-linux LIBS="-l/home/xx/work/tool/prelink/elflib_output/lib"

结果还是报错

checking libelf.h usability... no
checking libelf.h presence... no
checking for libelf.h... no
configure: error: libelf.h not found

对应的头文件找不到
得设置CFLAGS

./configure --prefix=/home/xx/work/tool/prelink/output --without-sysroot --host=arm-linux LIBS='-L/home/xx/work/tool/prelink/elflib_output/lib' CFLAGS='-I/home/xx/work/tool/prelink/elflib_output/include/'

设置CFLAGS 后能正确生成makefile
然后make -j 16
编译时又出现如下错误

/opt/fsl-imx-x11/3.14.52-1.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: cannot find -liberty

collect2: error: ld returned 1 exit status

下载binutils 编译对应的libiberty库
然后再来编译prelink

总结

交叉编译是比较麻烦的事情,各种依赖库,各种设置都要自己配置,而且在编译时容易出现各种各样莫名其妙的错误。是一件考验基本功和能力的事情。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux多线程服务端编程:使用muduo C++网络库》主要讲述采用现代C++在x86-64 Linux上编写多线程TCP网络服务程序的主流常规技术,重点讲解一种适应性较强的多线程服务器的编程模型,即one loop per thread。 目 录 第1部分C++ 多线程系统编程 第1章线程安全的对象生命期管理3 1.1当析构函数遇到多线程. . . . . . . . . . . . . . . . .. . . . . . . . . . . 3 1.1.1线程安全的定义. . . . . . . . . . . . . . . . .. . . . . . . . . . . 4 1.1.2MutexLock 与MutexLockGuard. . . . . . . . . . . . . . . . . . . . 4 1.1.3一个线程安全的Counter 示例.. . . . . . . . . . . . . . . . . . . 4 1.2对象的创建很简单. . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . 5 1.3销毁太难. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 7 1.3.1mutex 不是办法. . . . . . . . . . . . . . . . . . . .. . . . . . . . 7 1.3.2作为数据成员的mutex 不能保护析构.. . . . . . . . . . . . . . 8 1.4线程安全的Observer 有多难.. . . . . . . . . . . . . . . . . . . . . . . . 8 1.5原始指针有何不妥. . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . 11 1.6神器shared_ptr/weak_ptr . . . . . . . . . .. . . . . . . . . . . . . . . . 13 1.7插曲:系统地避免各种指针错误. . . . . . . . . . . . . . . . .. . . . . . 14 1.8应用到Observer 上.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.9再论shared_ptr 的线程安全.. . . . . . . . . . . . . . . . . . . . . . . . 17 1.10shared_ptr 技术与陷阱. . . .. . . . . . . . . . . . . . . . . . . . . . . . 19 1.11对象池. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . 21 1.11.1enable_shared_from_this . . . . . . . . . . . . . . . . . . . . . . 23 1.11.2弱回调. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . 24 1.12替代方案. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 26 1.13心得与小结. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . 26 1.14Observer 之谬. . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 第2章线程同步精要 2.1互斥器(mutex). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.1.1只使用非递归的mutex . . . . . . . . . . . . . .. . . . . . . . . . 33 2.1.2死锁. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . 35 2.2条件变量(condition variable). . . . . . . . . .

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值