Cross-compiling and porting of glib library based on FS4412 embedded system porting (6)

Source: Internet
Author: User
Tags ffi posix



Share with you today the cross-compilation process of the glib library and how to compile and run the program.



GLib Library of the transplant data is relatively small, relatively fragmented, here I will write a personal transplant process, and share with you. According to my process transplant should be no problem, if encountered a problem can leave a message to contact me, discuss the study.



Here to emphasize: libc, glibc, glib are different libraries!


GLIBC and libc are all C libraries under Linux, and glib is the base library for GTK +.
LIBC is the ANSI C function library under Linux, and GLIBC is the GUN C function library under Linux.


Specific distinctions and concepts can be consulted: HTTP://USER.QZONE.QQ.COM/452215612/2






Let's talk about my host computer environment:



Pc:xp SP3, Depth perfect pure Standard Edition
Virtual machines: VMware? Workstation, Version: 9.0.2 build-1031769
ubuntu:12.04



Before I have installed glib2.0.6 on Ubuntu, and have done some data structure related tutorials, interested can refer to the following blog post: http://blog.csdn.net/andylauren/article/category/6219334



Development Board Environment:



FS4412 Development Board: Samsung ARM Exynos 44,124-core processor, Linux3.14 kernel version,Uboot 2013.03,gcc-4.6.4 cross-compilation chain



Our ultimate goal is to be able to execute executable files using the GLib library on our Development Board.



To achieve this we need a few steps:



1, need to use cross-compilation chain cross-compiling glib library;



2. Add the generated dynamic library to the Lib directory of the file system;



3. Cross-Compile the. c file using the cross-compiled glib library, then execute the file in the Development Board;






Preparation before installation:



GLib Source Package: http://ftp.gnome.org/pub/gnome/sources/glib/2.24/



We're using glib-2.22.5.tar.gz here.



Libffi Source Package: https://www.sourceware.org/libffi/



Libffi is a dependent library of glib, so we need to cross-compile this library, we are using libffi-3.2.1.tar.gz



Installation of Pkg:
Pkg-config is a good text substitution command that is used primarily for compiling commands, which are described in more detail below
Installation: Apt-getinstall Pkg-config






Step one: cross-compiling the glib library



Before we cross-compile glib we need to cross-compile glib's dependent libraries Libffi


1, the installation of Libffi
The FFI is a library of glib dependencies that need to be cross-compiled before cross-compiling Libffi
First install the development Use command on the PC Libffi-dev
Type: Apt-getinstall Libffi-dev This step in order to solve the problem of configure, the following article is introduced.
Throw libffi-3.2.1.tar.gz into Ubuntu
Unzip the source and establish the installation path
It's nothing to look at. Start configuration operations Directly
Type: CC=ARM-LINUX-GCC./configure--prefix=/home/linux/glib/ffi/--host=arm-linux
You should not encounter any problems and then generate the makefile files that we need.
And then it's in the trilogy.
Make
Make Insall
To better use the libraries in the custom installation path at compile time, we use Pkg-config to help us compile glib, but to run pkg-config, we first need to make xx.pc files:
We first came to the installation directory under the Lib/pkgconfig directory, there is a libffi.pc file, because this library is for arm, so I am accustomed to the file name after adding-ARM:CP libffi.pc libffi-arm.pc
Then copy the libffi-arm.pc to the/usr/local/lib/pkgconfig/: CP libffi-arm.pc/usr/local/lib/pkgconfig/
So the pkg-config command can identify this file, you can first type Pkg-config--cflags libffi-arm see what will print?
-i/home/linux/glib/ffi/lib/libffi-3.2.1/include
This is the header file path that we need to use when we cross-compile.


2. Cross-compiling GLib library



As with the general installation, start using configure to generate makefile:
Decompression glib-2.22.5.tar.gz get glib-2.22.5 source package directory.
Create the cache file in the glib-2.22.5 directory first: Gedit Arm-linux.cache
Then enter in the file:
Glib_cv_stack_grows=no
Glib_cv_uscore=no
Ac_cv_func_posix_getpwuid_r=yes
Ac_cv_func_posix_getgrgid_r=yes
Glib_cv_have_qsort_r=no


When you run configure, the configuration is read from the cache file and the configured log is written to this file
Type the command: CC=ARM-LINUX-GCC./configure--prefix=/home/linux/glib/glib-2.22/--host=arm-linux--cache-file= Arm-linux.cache



You should not encounter any problems and generate a makefile file.



The glib-2.22 folder is then created under the GLib directory to hold the generated glib library files.



And then it's in the trilogy.
Make
Make Insall



This time you will see the cross-compiled glib library file under the glib-2.22 folder. There will be bin,include,lib,share four folders, respectively, we compile and run the files and libraries.



Step Two: Add the generated dynamic library to the file system's Lib directory



Now we need to put the compiled glib dynamic library into the NFS file system's Lib directory, so that our program can invoke the glib dynamic library when it executes on the development Board.



We enter the command cp/home/linux/glib/glib-2.22/lib/libglib-2.0*/nfs/rootfs/lib/
Here we copy all the libraries of GLib to NFS, including the static library, which is unnecessary, we just need to copy the dynamic library.



Where the file libglib-2.0.so is a hard link, so we directly copy this text will be in NFS to get a copy of the library file. The correct way is to copy the libglib-2.0.so.0.2200.5 file, and do two hard links to this file, the connection files are libglib-2.0.so.0 and libglib-2.0.so respectively.



In fact, the correct approach is to use the CP-A command, where the-a parameter is equivalent to-DPR, keep the file connection (d), keep the original file's properties (p) and do the recursive processing (R), so you should enter:
Cp-a/home/linux/glib/glib-2.22/lib/libglib-2.0*/nfs/rootfs/lib/
Then delete the static compilation library file libglib-2.0.la
Rm/home/linux/glib/glib-2.22/lib/libglib-2.0.la



Step three: cross-compile the. c file using the cross-compiled glib library, then execute the file in the Development Board



We now have a glib cross-compilation library, and there is a dynamic library in the NFS file system, and we need to compile a glib function with this library. c files and run them on the Development Board.



We're from http://blog.csdn.net/andylauren/article/category/. 6219334 Select a. c file as our source program, and then we need to know some compile-time parameters, such as header file path settings, library file path settings, at compile time use-I plus path to represent the path of the header file,-L represents the path of the library file.



On Ubuntu we used the method of compiling the glib library file as GCC Xxx.c-o xxx-lglib-2.0 here is the target file name generated after-O, which is not required, If you do not generate the A.out file,-L is the library file name used by our door, is the library file name is removed from the beginning of Lib, why we do not use-i-l, because we have put these files in the system default path, compile time will automatically go to the default path to find the corresponding file. When we cross-compile, we also need the corresponding writing compile command, here I first write out the command, and then in the explanation, compile the command as follows:



ARM-LINUX-GCC Gtree.c-o gtree-arm-i/home/linux/glib/glib-2.28/include/glib-2.0-i/home/linux/glib/glib-2.28/lib/ glib-2.0/include-l/home/linux/glib/glib-2.28/lib-lglib-2.0



Where ARM-LINUX-GCC is the cross-compilation of GCC, there is a ARM-NONE-LINUX-GNUEABI-GCC command, in fact, and it is exactly the same, behind we will explain to him;



GTREE.C is the source file we want to compile,-o gtree-arm the target file we want to generate;



-i/home/linux/glib/glib-2.28/include/glib-2.0-i/home/linux/glib/glib-2.28/lib/glib-2.0/include our header file path;



-l/home/linux/glib/glib-2.28/lib our library file path;



-lglib-2.0 The library file we call;



Then we copy the generated Gtree-arm file to the NFS file system directory, CP Gtree-arm/nfs/rootfs



Set the Development Board to NFS mount, and then we launch the board and run the./gtree-arm, haha see the results of the operation, and the results of the operation on the computer, it means that we transplanted successfully.





[[email protected] ]# ls
a.out              fs4412_led_app     mnt                sys
bin                fs4412_led_drv.ko  proc               tmp
dev                lib                root               usr
etc                linuxrc            sbin               var
[[email protected] ]# ./a.out 
12345
[[email protected] ]# ls
a.out              fs4412_led_drv.ko  proc               usr
bin                gtree-arm          root               var
dev                lib                sbin
etc                linuxrc            sys
fs4412_led_app     mnt                tmp
[[email protected] ]# ./gtree-arm 
BEGIN:
************************************************************
Now the tree:
Key:    0               Vaule:  zero
Key:    1               Vaule:  one
Key:    2               Vaule:  two
Key:    3               Vaule:  three
Key:    4               Vaule:  four
Key:    5               Vaule:  five
Key:    6               Vaule:  six
Key:    7               Vaule:  seven
Key:    8               Vaule:  eight
Key:    9               Vaule:  nine
The tree should have '10' items now.            Result: 10.
The height of tree is '4' now.
Now the vaule of '3' should be '3333' now.
Key:    0               Vaule:  zero
Key:    1               Vaule:  one
Key:    2               Vaule:  two
Key:    3               Vaule:  3333
Key:    4               Vaule:  four
Key:    5               Vaule:  five
Key:    6               Vaule:  six
Key:    7               Vaule:  seven
Key:    8               Vaule:  eight
Key:    9               Vaule:  nine
Now the vaule of '3' should be '3333' now[lookup].
The key '3' has been found and removed now.
Now the vaule which should be removed of '3' should be '(null)' now[search].
Now the tree look like:
Key:    0               Vaule:  zero
Key:    1               Vaule:  one
Key:    2               Vaule:  two
Key:    4               Vaule:  four
Key:    5               Vaule:  five
Key:    6               Vaule:  six
Key:    7               Vaule:  seven
Key:    8               Vaule:  eight
Key:    9               Vaule:  nine

************************************************************
DONE
[[email protected] ]# 







The first transplant of the Blood and tears history:
Let me tell you about the problem I encountered during the transplant, it can be said that a step by cut, ten steps a pit, there is water in the pit, water and ding, there is no shadow. It feels like a 99,81 to experience a western paradise.


First on the net can not find a complete glib transplant tutorial, and some are just a few words, I am here groping forward.



First robbery: Version selection



First I think my Ubuntu is installed on the glib2.0.6, then I also use this to transplant it, and then I began to decompress, configure./configure, and then encountered a problem that could not find the answer at all,



Checking for extra flags to get ANSI library prototypes ... configure:error:cannot run test program when cross compiling



In the Internet can not find the corresponding solution, and even the posts are not, no way, I changed the version, Glib2.0.7,glib2.12, this is all, I try to read, meaning that a test file can not be run in a cross-compilation environment, really do not know what the situation, I think it should, glib low version and cross-compilation chain or the compilation environment does not match, or the lower version does not support cross-compilation.



Good I changed the latest version of the glib2.48, error missing zlib lib and header files, for multiple versions, from glib2.32 to glib2.28 are so, finally I found a post on the Internet glib-2.23 need zlib, that is, I also need to cross-compile zlib, I think, this Zli b still do not know what will meet the dangers, give up the latest version, anyway, I am not a Virgo, as long as there is a good library can be, do not need to be the latest. Then the 2.22.5 version was selected in the version after 2.23.



Here I just write less than 100 words, but should be able to imagine I am doing time and again to download, and then into the Ubuntu virtual machine, and then XVF decompression, and then./configure, and then looked at the various errors is the mood, I download the experiment version of not less than 20, it is a crash.



Second robbery: Download URLs and autoconf



At the beginning I download the source package through the official download URL they provided, but some of the source packages have configure files, And some only configure.ac files, this configure.ac file is required autoconf tool to generate configure, I am afraid I choose the version has a problem, all deliberately installed autoconf tool to generate configure.



This time the problem comes again, autoconf tool generated configure process has an error, my God Ah, really cue unravelling, but I do not intend to issue nested processing, I gave up the use of autoconf, and then I went to find other download source package website, Finally, I found a website that provides all the source packages with configure files, which is the URL I posted above.



When I meet another problem in order to solve a problem, I wonder what the mood is when the CPU interrupts the nesting. Must be very crash, no wonder A9 will not support the interrupt nesting later.



Third robbery: cross-compilation parameters



In fact, I am just a beginner, in the study of the use of teachers to configure the environment, as long as a GCC are done, where to use their own to your change files, library files. Contact with the cross-compilation after this is a difficult hurdle, you must be able to specify the header file and library file path, this robbery is more than better, after all, is the basic knowledge, online information tutorials a lot.






In the end I am adding a knowledge that I find myself, that ARM-LINUX-GCC and ARM-NONE-LINUX-GUNEABI-GCC are actually the same thing.



We use which ARM-LINUX-GCC



See/HOME/LINUX/SYS/GCC-4.6.4/BIN/ARM-LINUX-GCC



Description ARM-LINUX-GCC points to the ARM-LINUX-GCC in the Bin folder in the cross-compilation chain



Then we use ARM-LINUX-GCC-V.





[email protected]:~/16021/glibDemo$ arm-linux-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gcc
COLLECT_LTO_WRAPPER=/home/linux/sys/gcc-4.6.4/bin/../libexec/gcc/arm-arm1176jzfssf-linux-gnueabi/4.6.4/lto-wrapper
Target: arm-arm1176jzfssf-linux-gnueabi
Configured with: /work/builddir/src/gcc-4.6.4/configure 
--build=i686-build_pc-linux-gnu 
--host=i686-build_pc-linux-gnu 
--target=arm-arm1176jzfssf-linux-gnueabi 
--prefix=/opt/TuxamitoSoftToolchains/arm-arm1176jzfssf-linux-gnueabi/gcc-4.6.4 
--with-sysroot=/opt/TuxamitoSoftToolchains/arm-arm1176jzfssf-linux-gnueabi/gcc-4.6.4/arm-arm1176jzfssf-linux-gnueabi/sysroot 
--enable-languages=c,c++ 
--with-arch=armv6zk 
--with-cpu=arm1176jzf-s 
--with-tune=arm1176jzf-s 
--with-fpu=vfp 
--with-float=softfp 
--with-pkgversion='crosstool-NG hg+default-2685dfa9de14 - tc0002' 
--disable-sjlj-exceptions 
--enable-__cxa_atexit 
--disable-libmudflap 
--disable-libgomp 
--disable-libssp 
--disable-libquadmath 
--disable-libquadmath-support 
--with-gmp=/work/builddir/arm-arm1176jzfssf-linux-gnueabi/buildtools 
--with-mpfr=/work/builddir/arm-arm1176jzfssf-linux-gnueabi/buildtools 
--with-mpc=/work/builddir/arm-arm1176jzfssf-linux-gnueabi/buildtools 
--with-ppl=/work/builddir/arm-arm1176jzfssf-linux-gnueabi/buildtools 
--with-cloog=/work/builddir/arm-arm1176jzfssf-linux-gnueabi/buildtools 
--with-libelf=/work/builddir/arm-arm1176jzfssf-linux-gnueabi/buildtools 
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' 
--enable-threads=posix 
--enable-target-optspace 
--without-long-double-128 
--disable-nls 
--disable-multilib 
--with-local-prefix=/opt/TuxamitoSoftToolchains/arm-arm1176jzfssf-linux-gnueabi/gcc-4.6.4/arm-arm1176jzfssf-linux-gnueabi/sysroot 
--enable-c99 
--enable-long-long
Thread model: posix
gcc version 4.6.4 (crosstool-NG hg+default-2685dfa9de14 - tc0002) 

Okay, we're using arm-none-linux-guneabi-gcc-v.





As with the return above, all paths are the same, the main one being the Target:arm-arm1176jzfssf-linux-gnueabi, the targets are identical, So when we need to use arm-none-linux-guneabi-, we just need to use arm-linux-.















Cross-compiling and porting of glib library based on FS4412 embedded system porting (6)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.