Ubuntu18.04交叉编译glib

Ubuntu18.04交叉编译glib

源码下载

glib下载地址:https://download.gnome.org/sources/glib/2.45/
libffi下载地址:ftp://sourceware.org/pub/libffi/

交叉编译glib需要依赖libffi,首先对libffi进行交叉编译

交叉编译libffi

解压下载的源码,进入解压目录:
执行./configure -h查看configure选项如下:

`configure' configures libffi 3.3 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/libffi]
  --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-builddir      disable automatic build in subdir of sources

  --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)
  --enable-portable-binary
                          disable compiler optimizations that would produce
                          unportable binaries
  --enable-maintainer-mode
                          enable make rules and dependencies not useful (and
                          sometimes confusing) to the casual installer
  --enable-pax_emutramp       enable pax emulated trampolines, for we can't use PROT_EXEC
  --disable-docs          Disable building of docs (default: no)
  --enable-debug          debugging mode
  --disable-structs       omit code for struct support
  --disable-raw-api       make the raw api unavailable
  --enable-purify-safety  purify-safe mode
  --disable-multi-os-directory
                          disable use of gcc --print-multi-os-directory to change the library installation directory
  --enable-symvers=STYLE  enables symbol versioning of the shared library
                          [default=yes]

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-gcc-arch=<arch>  use architecture <arch> for gcc -march/-mtune,
                          instead of guessing

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
  CCAS        assembler compiler command (defaults to CC)
  CCASFLAGS   assembler compiler flags (defaults to CFLAGS)
  LT_SYS_LIBRARY_PATH
              User-defined run-time library search path.
  CPP         C preprocessor
  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.

Report bugs to <http://github.com/libffi/libffi/issues>.

可以根据自己的需求选择不同的配置选项,这里主要配置交叉编译器,一种可以通过命令行直接配置,另一种可以先生成Makefile文件,然后对Makefile进行修改,我是对Makefile直接配置,如下:

./configure --prefix=$PWD/output //生成Makefile

vim Makefile //打开Makefile
//搜索到CC=,修改为自交交叉编译器的绝对路径,如下:
CC = /media/gree/47037fce-de1d-40bd-8cd8-922f0e1edc8e/rk_docs/rk1808-sdk/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
//接着修改CXX、nm等,修改完保存退出
//编译安装
make
make install

完成之后会在output目录生成如下:

include  lib  lib64  share

交叉编译glib

解压进入源码目录:
添加有关配置文件Vim glib.cache

glib_cv_long_long_format=ll
glib_cv_stack_grows=no
glib_cv_have_strlcpy=no
glib_cv_have_qsort_r=yes
glib_cv_va_val_copy=yes
glib_cv_uscore=no
glib_cv_rtldglobal_broken=no
ac_cv_func_posix_getpwuid_r=yes
ac_cv_func_posix_getgrgid_r=yes

和编译libffi同样的方法,先执行./configure -h查看配置选项,根据需要进行配置,如下:

./configure --prefix=$PWD/output CC=/media/gree/47037fce-de1d-40bd-8cd8-922f0e1edc8e/rk_docs/rk1808-sdk/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc --host=aarch64-linux-gnu CXX=/media/gree/47037fce-de1d-40bd-8cd8-922f0e1edc8e/rk_docs/rk1808-sdk/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ LIBFFI_CFLAGS="-I/home/gree/wangjy/gstreamer/libffi-3.3/output/include" LIBFFI_LIBS="-lffi-L/home/gree/wangjy/gstreamer/libffi-3.3/output/lib" ZLIB_CFLAGS="-I/home/gree/wangjy/arm_opencv/OPENCV_3THPARTY_LIB/zlib/include" ZLIB_LIBS="-lz -L/home/gree/wangjy/arm_opencv/OPENCV_3THPARTY_LIB/zlib/lib" --cache-file=glib.cache  --disable-selinux  --disable-xattr --disable-libelf

生成Makefile,修改Makefile,然后编译安装。

make
make install

其他问题

1、编译glib的时候会出现以下错误:

gdate.c: In function 'g_date_strftime':
gdate.c:2497:7: error: format not a string literal, format string not checked [-Werror=format-nonliteral]
      tmplen = strftime (tmpbuf, tmpbufsize, locale_format, &tm);
      ^~~~~~
cc1: some warnings being treated as errors

这个错误与编译器无关,改下源码即可:
打开报错的文件,找到g_date_strftime函数定义的地方,在前后加上如下内容,重新编译即可。

+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+
 gsize     
 g_date_strftime (gchar       *s, 
                  gsize        slen, 
@@ -2549,3 +2552,5 @@ g_date_strftime (gchar       *s,
   return retval;
 #endif
 }
+
+#pragma GCC diagnostic pop

2、编译glib出现动态库未找到错误,如下:

CCLD     gobject-query
./.libs/libgobject-2.0.so: undefined reference to `ffi_type_void'
./.libs/libgobject-2.0.so: undefined reference to `ffi_type_double'
./.libs/libgobject-2.0.so: undefined reference to `ffi_prep_cif'
./.libs/libgobject-2.0.so: undefined reference to `ffi_type_sint32'
./.libs/libgobject-2.0.so: undefined reference to `ffi_type_float'
./.libs/libgobject-2.0.so: undefined reference to `ffi_type_uint64'
./.libs/libgobject-2.0.so: undefined reference to `ffi_type_sint64'
./.libs/libgobject-2.0.so: undefined reference to `ffi_type_pointer'
./.libs/libgobject-2.0.so: undefined reference to `ffi_type_uint32'
./.libs/libgobject-2.0.so: undefined reference to `ffi_call'
collect2: error: ld returned 1 exit status

解决:将libffi在本地编译安装下,重新编译glib即可。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值