Author: Mugabi Siro

Category: GNU/Linux Toolchain

Summary:

Installing Ubuntu's native C/C++ GNU/Linux toolchain components. Performed on Ubuntu 12.04 AMD64.

Tags: gnu/linux toolchain gnu linux ubuntu

Toolchain Install on x86 (64-Bit)

Installing the compiler, binutils and C library components of the native toolchain in Ubuntu can be done via the build-essential package1:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential

This command will result in the installation of a native toolchain:

  • gcc GNU C compiler (packaged by major.minor versions e.g. gcc-4.6) and g++ GNU C++ compiler (packaged by major.minor versions e.g. g++-4.6). As of the Ubuntu 11.10 (maverick) release, GCC packages are based on the Linaro GCC branch. The branch is used to build packages on all architectures.

Note that Ubuntu sets some compiler flags differently compared to GCC upstream releases.

  • Binutils - GNU assembler (as), GNU linker (ld) and other utilities such as addr2line, ar, gprof, nm, objcopy, objdump, ranlib, readelf, size, strings, strip, etc.

  • libc6-dev - eglibc : Development Libraries and Header Files. The [/lib] and [/usr/lib] on Ubuntu x86_64 platforms contain 64-bit library (development) files. The /lib64 just contains a symlink to /lib/x86_64-linux-gnu/ld-2.15.so.

alongside several other development related utilities:

  • make - A utility for Directing compilation.

  • dpkg-dev - Debian package development tools

  • patch - Apply a diff file to an original

  • And many more.

See this link or run:

$ cat /usr/share/build-essential/essential-packages-list

for details.

For instructions on installing other compilers e.g. gcj, g77, gfortran, etc, follow this link.

Kernel headers for userspace development are required to complete the installation of the core components of the toolchain:

$ sudo apt-get install linux-libc-dev

Although not a core component of the toolchain, the GNU Debugger gdb is a useful tool to have around and can be installed via:

$ sudo apt-get install gdb

Installing 32-bit development files on x86_64

The installed GCC compilers can generate 32-bit binaries on 64-bit platforms via the -m32 option. However, additional package support is required:

  • multilib

    These are compiler runtime packages e.g. gcc-[VERSION-]multilib, g++-[VERSION-]multilib.

  • 32-bit version of eglibc and its development headers.

  • 32-bit versions of other (development) libraries depending on your 32-bit target application's requirements. These start with lib32. Try running:

    $ apt-cache search lib32 
    lib32asound2 - shared library for ALSA applications (32 bit)
    lib32asound2-dev - shared library for ALSA applications -- development files (32 bit)
    lib32bz2-1.0 - high-quality block-sorting file compressor library - 32bit runtime
    lib32bz2-dev - high-quality block-sorting file compressor library - 32bit development
    lib32ffi-dev - Foreign Function Interface library (development files, 32bit)
    lib32ffi6 - Foreign Function Interface library runtime (32bit)
    lib32gcc1 - GCC support library (32 bit Version)
    lib32gcc1-dbg - GCC support library (debug symbols)
    lib32gfortran3 - Runtime library for GNU Fortran applications (32bit)
    lib32gfortran3-dbg - Runtime library for GNU Fortran applications (32 bit debug symbols)
    

So, to install core components of a 32-bit toolchain:

$ sudo apt-get install ia32-libs libc6-i386 libc6-dev-i386 lib32gcc1 gcc-multilib lib32stdc++6 g++-multilib

where:

  • Compiler Support:

    lib32gcc1 (32-bit version gcc support library), gcc-multilib (GNU C compiler multilib files), lib32stdc++6 (32-bit version of GNU standard C++ library), g++-multilib (GNU C++ compiler multilib files).

  • Libraries:

    ia32-lib (various libraries needed for compiling the 32-bit guest additions), libc6-dev-i386 (Embedded GNU C Library: 32-bit development libraries for AMD64), libc6-i386 (Embedded GNU C Library: 32-bit shared libraries for AMD64).

Toolchain Install on x86 (32-Bit)

The instructions in the previous section can be mirrored for toolchain installation on a 32-bit Ubuntu 12.04 platform. Development for 64-bit (x86_64) targets is also possible from 32-bit platforms. However, note that it is not possible to (directly) run 64-bit binaries on a 32-bit platform.

Follow this link for instructions on installing a 64-bit toolchain on 32-bit Ubuntu.

Development manpages

If missing, development manpages can be installed via:

$ sudo apt-get install manpages-dev manpages-posix-dev

Installing Distro Kernel Development Headers

To perform kernel related development against the distro kernel image, you will require its development headers. If these have not yet been installed, you may run:

$ VERSION=`uname -r`
$ sudo apt-get install linux-headers-${VERSION}

Miscallenous Utilities

There are a number of other packages that are often required during embedded development. A few are listed below.

  • autoconf - automatic configure script builder:

    $ sudo apt-get install autoconf
    
  • automake - A tool for generating GNU Standards-compliant Makefiles:

    $ sudo apt-get install automake1.9
    
  • Bison - A YACC-compatible parser generator:

    $ sudo apt-get install bison
    
  • Flex - A fast lexical analyzer generator.

    $ sudo apt-get install flex
    
  • libtool - A generic library support script

    $ sudo apt-get install libtool
    
  • libncurses - Shared libraries for terminal handling:

    $ sudo apt-get install libncurses5 libncurses5-dev
    
  • Version/Revision Control Systems:

    $ sudo apt-get install git subversion cvs
    
  • And even more e.g:

    $ sudo apt-get install gperf gettext texinfo [k]cscope
    

Resources

  • https://wiki.ubuntu.com/ToolChain
  • https://wiki.ubuntu.com/ToolChain/CompilerFlags
  • https://help.ubuntu.com/community/InstallingCompilers
  • http://packages.ubuntu.com/precise/gcc

Footnotes

1. See apt-get(8) for the meaning of the commands used here. [go back]