交叉编译sysbench

/ 0评 / 3

我觉得这个应该有个副标题configure,make,make install型交叉编译方法指导,指导一个思想,而不是所有都改好提供,很多人不求甚解,不知道如何去交叉编译各种程序,嵌入式平台就是麻烦,没有什么apt-get一下子就装好了.空间也不大,所以才有交叉编译.一般对于这种需要configure的,首先我有一份sysbench的源码,然而我需要解压,干净的.

QQ截图20150628120341

发现文件分布如下:

ater@tater-VirtualBox:~/work/sysbench/sysbench-0.5$ ls
autogen.sh  config        COPYING  install-sh  Makefile.am  mkinstalldirs  README-WIN.txt  TODO
ChangeLog   configure.ac  doc      m4          missing      README.md      sysbench

查看autogen.sh,发现没有和编译器相关的痕迹,但是用了一些库,获取库信息,没关系的,平台无关:

#!/usr/bin/env bash
# Taken from lighthttpd server (BSD). Thanks Jan!
# Run this to generate all the initial makefiles, etc.
die() { echo "$@"; exit 1; }
ACLOCAL_FLAGS="-I m4"
LIBTOOLIZE_FLAGS="--copy --force"
AUTOMAKE_FLAGS="-c --foreign --add-missing"
ARGV0=$0
ARGS="$@"
run() {
	echo "$ARGV0: running `$@' $ARGS"
	$@ $ARGS
}
## jump out if one of the programs returns 'false'
set -e
if test x$ACLOCAL = x; then
  if test ! "x`which aclocal-1.10 2> /dev/null | grep -v '^no'`" = x; then
    ACLOCAL=aclocal-1.10
  elif test ! "x`which aclocal110 2> /dev/null | grep -v '^no'`" = x; then
    ACLOCAL=aclocal110
  elif test ! "x`which aclocal 2> /dev/null | grep -v '^no'`" = x; then
    ACLOCAL=aclocal
  else
    echo "automake 1.10.x (aclocal) wasn't found, exiting"; exit 1
  fi
fi
if test x$LIBTOOLIZE = x; then
  if test ! "x`which libtoolize15 2> /dev/null | grep -v '^no'`" = x; then
    LIBTOOLIZE=libtoolize15
  elif test ! "x`which libtoolize14 2> /dev/null | grep -v '^no'`" = x; then
    LIBTOOLIZE=libtoolize14
  elif test ! "x`which glibtoolize 2> /dev/null | grep -v '^no'`" = x; then
    LIBTOOLIZE=glibtoolize
  elif test ! "x`which libtoolize 2> /dev/null | grep -v '^no'`" = x; then
    LIBTOOLIZE=libtoolize
  else
    echo "libtoolize 1.4+ wasn't found, exiting"; exit 1
  fi
fi
if test x$AUTOMAKE = x; then
  if test ! "x`which automake-1.10 2> /dev/null | grep -v '^no'`" = x; then
    AUTOMAKE=automake-1.10
  elif test ! "x`which automake110 2> /dev/null | grep -v '^no'`" = x; then
    AUTOMAKE=automake110
  elif test ! "x`which automake 2> /dev/null | grep -v '^no'`" = x; then
    AUTOMAKE=automake
  else
    echo "automake 1.10.x wasn't found, exiting"; exit 1
  fi
fi
## macosx has autoconf-2.59 and autoconf-2.60
if test x$AUTOCONF = x; then
  if test ! "x`which autoconf-2.59 2> /dev/null | grep -v '^no'`" = x; then
    AUTOCONF=autoconf-2.59
  elif test ! "x`which autoconf259 2> /dev/null | grep -v '^no'`" = x; then
    AUTOCONF=autoconf259
  elif test ! "x`which autoconf 2> /dev/null | grep -v '^no'`" = x; then
    AUTOCONF=autoconf
  else
    echo "autoconf 2.59+ wasn't found, exiting"; exit 1
  fi
fi
if test x$AUTOHEADER = x; then
  if test ! "x`which autoheader-2.59 2> /dev/null | grep -v '^no'`" = x; then
    AUTOHEADER=autoheader-2.59
  elif test ! "x`which autoheader259 2> /dev/null | grep -v '^no'`" = x; then
    AUTOHEADER=autoheader259
  elif test ! "x`which autoheader 2> /dev/null | grep -v '^no'`" = x; then
    AUTOHEADER=autoheader
  else
    echo "autoconf 2.59+ (autoheader) wasn't found, exiting"; exit 1
  fi
fi
run $ACLOCAL $ACLOCAL_FLAGS || die "Can't execute aclocal"
run $LIBTOOLIZE $LIBTOOLIZE_FLAGS || die "Can't execute libtoolize"
run $AUTOHEADER || die "Can't execute autoheader"
run $AUTOMAKE $AUTOMAKE_FLAGS  || die "Can't execute automake"
run $AUTOCONF || die "Can't execute autoconf"
echo -n "Libtoolized with: "
$LIBTOOLIZE --version | head -1
echo -n "Automade with: "
$AUTOMAKE --version | head -1
echo -n "Configured with: "
$AUTOCONF --version | head -1

交叉编译思路,如下:

./configure --build=arm-fsl-linux --host=arm CC=/opt/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-fsl-linux-gnueabi-gcc

需要根据实际替换环境,如上,我是编译fsl的板子,目标平台是arm,编译器路径就是CC指定的,当然不是执行就万事大吉,还要注意红框地方对不对,还有上下文是否有报错.

QQ截图20150628121003

编译过程注意一下是不是你要的:

QQ截图20150628122030

发生一个错误:

/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status
make[2]: *** [sysbench] 错误 1
make[2]:正在离开目录 `/home/tater/work/sysbench/sysbench-0.5/sysbench'
make[1]: *** [all-recursive] 错误 1
make[1]:正在离开目录 `/home/tater/work/sysbench/sysbench-0.5/sysbench'
make: *** [all-recursive] 错误 1
tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5$ 

好吧,我们没MySQL的哦,所以...查看一下configure参数.

tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5$ ./configure --help
`configure' configures sysbench 0.5 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]
  --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/sysbench]
  --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]
  --disable-dependency-tracking  speeds up one-time build
  --enable-dependency-tracking   do not reject slow dependency extractors
  --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)
  --enable-largefile      enable large files support (default is enabled)
  --enable-aio            enable Linux asynchronous I/O support (default is
                          enabled)
  --disable-rpath         do not hardcode runtime library paths
  --disable-largefile     omit support for large files
  --enable-profiling      Toggle profiling [default=off]
  --enable-coverage       Toggle coverage [default=off]
  --disable-pedantic-warnings
                          Toggle pedanticness [default=on]
  --enable-iso-pedantic-warnings
                          Toggle iso pedanticness [default=off]
  --enable-unreachable    Enable warnings about unreachable code [default=no]
  --disable-fail          Turn warnings into failures [default=no]
  --disable-go-crazy      Enables extra little warnings that might be too much
                          [default=on]
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-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-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
  --without-lib-prefix    don't search for libraries in includedir and libdir
  --with-extra-ldflags    additional linker flags, e.g. -all-static
  --with-mysql            compile with MySQL support (default is enabled)
  --with-drizzle          compile with Drizzle support (default is enabled)
  --with-attachsql        compile with libattachsql support (default is
                          enabled)
  --with-oracle           compile with Oracle support (default is disabled)
  --with-pgsql            compile with PostgreSQL support (default is
                          disabled)
  --with-lua              Compile with Lua scripting support (default is
                          enabled)
  --with-mysql-includes   path to MySQL header files
  --with-mysql-libs       path to MySQL libraries
  --with-gnu-ld           assume the C compiler uses GNU ld default=no
  --with-libdrizzle-prefix[=DIR]  search for libdrizzle in DIR/include and DIR/lib
  --without-libdrizzle-prefix     don't search for libdrizzle in includedir and libdir
  --with-libattachsql-prefix[=DIR]  search for libattachsql in DIR/include and DIR/lib
  --without-libattachsql-prefix     don't search for libattachsql in includedir and libdir
  --with-pgsql-includes   path to PostgreSQL header files
  --with-pgsql-libs       path to PostgreSQL libraries
  --with-debug            Add debug code/turns off optimizations (yes|no)
                          [default=no]
Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L if you have libraries in a
              nonstandard directory 
  LIBS        libraries to pass to the linker, e.g. -l
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I if
              you have headers in a nonstandard directory 
  CPP         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.
Report bugs to .
tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5$

根据提示,既然有--with-mysql,就有--without-mysql,所以再configure一次,加这个参数.再进行make时候,错误:

/home/tater/work/sysbench/sysbench-0.5/sysbench/sysbench.c:996: undefined reference to `rpl_malloc'
sb_options.o: In function `new_option':
/home/tater/work/sysbench/sysbench-0.5/sysbench/sb_options.c:404: undefined reference to `rpl_malloc'
sb_options.o: In function `new_value':
/home/tater/work/sysbench/sysbench-0.5/sysbench/sb_options.c:392: undefined reference to `rpl_malloc'
sb_logger.o: In function `oper_handler_init':
/home/tater/work/sysbench/sysbench-0.5/sysbench/sb_logger.c:497: undefined reference to `rpl_malloc'
/home/tater/work/sysbench/sysbench-0.5/sysbench/sb_logger.c:498: undefined reference to `rpl_malloc'
db_driver.o:/home/tater/work/sysbench/sysbench-0.5/sysbench/db_driver.c:721: more undefined references to `rpl_malloc' follow
collect2: ld returned 1 exit status
make[2]: *** [sysbench] 错误 1
make[2]:正在离开目录 `/home/tater/work/sysbench/sysbench-0.5/sysbench'
make[1]: *** [all-recursive] 错误 1
make[1]:正在离开目录 `/home/tater/work/sysbench/sysbench-0.5/sysbench'
make: *** [all-recursive] 错误 1
tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5$ 

好吧,没有rpl_malloc,这个打开configure,发现$as_echo "#define malloc rpl_malloc" >>confdefs.h,删掉或者注视掉吧.如果别的程序遇到这样的,就要看条件,如果是判断,就看判断上层,像这个直接没判断呢~ 然后需要重新configure和make,然后成功了,没什么错误了,就新建一个_install目录.

QQ截图20150628123158

然后执行安装:

make install DESTDIR=/home/tater/work/sysbench/sysbench-0.5/_install

里面的全部都可以复制到目标系统rootfs,但是其实只有bin有效:

tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5/_install$ tree
.
└── usr
    └── local
        ├── bin
        │   └── sysbench
        └── share
            └── doc
                └── sysbench
                    └── manual.html
6 directories, 2 files
tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5/_install$ 

最节省,只复制可执行文件~检查一下可执行文件是否就是要的目标文件:

tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5/_install/usr/local/bin$ file sysbench
sysbench: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, not stripped
tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5/_install/usr/local/bin$ ls -alh
总用量 2.8M
drwxrwxr-x 2 tater tater 4.0K  6月 28 12:33 .
drwxrwxr-x 4 tater tater 4.0K  6月 28 12:33 ..
-rwxr-xr-x 1 tater tater 2.8M  6月 28 12:33 sysbench
tater@tater-VirtualBox:~/work/sysbench/sysbench-0.5/_install/usr/local/bin$ 

复制到平台里面,测试:

QQ截图20150628124127

这一类大概都是这么编译哦~

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注