最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

HOWTO for setting up a Cross Development Environment on Debian GNU/Linux

工作和技术 crifan 1908浏览 0评论

HOWTO for setting up a Cross Development Environment on Debian GNU/Linux

By Mobilab Research Group

Table of Contents

Introduction
Preparations
Setting up binutils, libc and the compiler
binutils
libc
Creating dummy packages
gcc

g++

Setting up additional cross development libraries

Install libraries
Try it out
Reference

Introduction

In this HOWTO, we will explain how to set up a cross development environment for the ARM platform including the use of libglib2.0. The ARM processor can be found in a number of embedded devices and PDAs, e.g. the Zaurus and the iPAQ.

Note

All packages and versions are related to Debian SID.

Preparations

First, install toolchain-source and dpkg-cross. Because toolchain-source depends on dpkg-cross, the following command will do:Optionally, install the package toolchain-source-gdb, if you believe in debugging.

# apt-get install toolchain-source

The toolchain-source package contains the source code of the current gcc and binutils. Additionally, it provides commands assisting in building cross compilers and binutils.

The dpkg-cross package is a tool for installing libraries and headers for cross compiling in special directories.

We had a problem with building gcc with autoconf version 2.54, so we recommend to:

# apt-get install autoconf2.13

For building the actual cross development packages, you will need fakeroot or a similar program. Because fakeroot will be used by default, just do this:

# apt-get install fakeroot

The only configuration, that is necessary now, is to change the crossbase in the file /etc/dpkg/cross-compile. The default value /usr/local should be changed:

crossbase = /usr

Setting up binutils, libc and the compiler

binutils

Now unpack and build binutils and compilers.

# cd /usr/src/; tpkg-make arm-linux

New directories binutils-arm-linux-2.13.90.x.y/ and gcc-arm-linux-3.2.z/ appear.

Adjust the user name in {binutils-arm-linux-2.13.90.x.y,gcc-arm-linux-3.2.z}/debian/{changelog,control}, if necessary. You might get an error when signing the package, if the user name is not correct. You may use pga tool for creating a secret key, if you haven’t one.

If you have to pass parameters to the configure or make process of binutils, change the files binutils-arm-linux-2.13.90.x.y/debian/rules.

Now do:

# cd binutils-arm-linux-2.13.90.0.4/; debuild -uc -us

This will configure, compile and build the cross binutils. To build the compiler, you have to install the resulting package first:

# debi

libc

The compiler needs also the target system C library to build. This library can easily be installed using tpkg-install-libc.

# tpkg-install-libc arm-linux

This command will download the libraries for the arm-linux platform from the british Debian server ftp.uk.debian.org, but the server can be changed via the environment variable TPKG_SERVER. The downloaded packages will automatically converted and installed by dpkg-cross.

Creating dummy packages

The dependencies of libc6 and libc6-dev are already fulfilled by libc6-arm-cross and libc6-dev-arm-cross, the dependency libglib2.0-0 will be fulfilled anyway. That leaves pkg-config. A cross version of pkg-config does not make sense, because the only important thing is the output of the command itself. This depends on the contents of the .pc files. Therefore it is sufficient to create a dummy package that depends on pkg-config. Install the equivs package:

# apt-get install equivs

With this little script (just fix your address and the target platform), you can build the dummy package:

<a name="mkXdummy"></a>#!/bin/sh

<span>EMAIL='You &lt;[email protected]&gt;'</span>
<span>TARGET=arm-cross</span>
<span>if [ -z &quot;$1&quot; ]; then echo &quot;no package&quot;; exit -1; fi</span>
<span>PACKAGE=$1</span>
<span>VERSION=`dpkg-query -W --showformat='${Version}' $PACKAGE | sed 's/-.*/-1/'`</span>
<span>echo &quot;Section: devel</span>
<span>Priority: optional</span>
<span>Standards-Version: 3.6.1.0</span>
<span>Package: $PACKAGE-$TARGET</span>
<span>Version: $VERSION</span>
<span>Maintainer: $EMAIL</span>
<span>Depends: $PACKAGE</span>
<span>Architecture: all</span>
<span>Description: Dummy $PACKAGE for $TARGET&quot; &gt; $PACKAGE-$TARGET.$$</span>
<span>equivs-build $PACKAGE-$TARGET.$$ &amp;&amp; rm -rf ./equivs/ $PACKAGE-$TARGET.$$</span>
$ mkXdummy pkg-config

Then, you have to install the dummy package:

# dpkg -i pkg-config-arm-cross_0.15.0-2_all.deb

Similar actions are necessary for tools, that are not platform-dependent, such as bison, flex, indent.

gcc

Now do:

# cd ../gcc-arm-linux-3.3.z/
<span># debuild</span>

Again, the package installs via:

# debi

Now you should have a cross development environment for C language.

g++

You have to enable C++ language in gcc-arm-linux-3.3.z/debian/rules file:

--enable-languages=c++

Rebuild gcc :

# debuild
<span># debi</span>

Install arm-linux libstdc++ library:

# cd /usr/arm-linux/lib
<span># tar xvzf &lt;PATH&gt;/libstdc++.tar.gz</span>

Install templates and header files:

# cd /usr/arm-linux/include
<span># tar xvzf &lt;PATH&gt;/include_g++.tar.gz</span>

Now you should have a cross development environment for C++ language.

Setting up additional cross development libraries

There are not many programs a user really wants without the need for more library dependencies than just the standard C library. A typical additional library is glib2 which is used by GTK+ and GNOME.

Before you can start with the library, you have to analyse its dependencies:

$ apt-cache show libglib2.0-0|grep ^Depends:
<span>Depends: libc6 (&gt;= 2.3.1-1)</span>
<span>$apt-cache show libglib2.0-dev|grep ^Depends:</span>
<span>Depends: libglib2.0-0 (= 2.0.7-1), libc6-dev | libc-dev, pkg-config</span>

The dependency on pkg-config-arm-cross can be fulfilled by a dummy package (see above). The output of pkg-config depends only on the contents of the .pc files.

Install libraries

Try to install libglib2.0-0 and libglib2-dev:

# tpkg-install-libc arm-linux 'libglib2.0-0$ libglib2-dev$'

The dollar signs are necessary for the tool as are the single quotes.

The cross compilation environment should now be complete.

Try it out

You can see the CFLAGS for cross compilation easily:

$ PKG_CONFIG_PATH=/usr/arm-linux/lib/pkgconfig pkg-config --cflags glib-2.0
<span>-I/usr/arm-linux/include/glib-2.0 -I/usr/arm-linux/lib/glib-2.0/include</span>

For packages, that come with a simple Makefile, use CC and CFLAGS=`pkg-config --cflags glib-2.0` etc., compilation is straight forward:

$ CC=/usr/bin/arm-linux-gcc 
<span>PKG_CONFIG_PATH=/usr/arm-linux/lib/pkgconfig make</span>

For packages based on autoconf, it should be easy as well:

$ CC=/usr/bin/arm-linux-gcc 
<span>PKG_CONFIG_PATH=/usr/arm-linux/lib/pkgconfig ./configure; make</span>

Unfortunately, not all packages are build in a way, that supports cross compilation. For these packages, you should fix the build process and send patches to the packages authors.

Reference

This HOWTO is based on this article.

转载请注明:在路上 » HOWTO for setting up a Cross Development Environment on Debian GNU/Linux

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
79 queries in 0.183 seconds, using 22.14MB memory