POPT command line utility

Introduction

This tutorial introduces the way to cross compile the POPT command line utility on an GNU Linux embedded platform.
The host machine will be a PC on which a GNU Linux distribution is installed.
The embedded platform might be constructed on top of one of the following architectures: arm, mips, mipsel, ppc or sparc.

POPT home page: http://freshmeat.net/projects/popt.

The latest available release (I presume) at the time of writing of this tutorial is 1.13 (January 05 2008).

Release 1.10.4 can be downloaded by typing the following command:

wget http://rpm.net.in/mirror/rpm-4.4.x/popt-1.10.4.tar.gz

Overview

Popt is a C library for parsing command line parameters. Popt was heavily influenced by the getopt() and getopt_long() functions, yet, it allow more powerful argument expansion.
Popt can parse arbitrary argv[] style arrays and automatically set variables based on command line arguments.
Popt allows command line arguments to be aliased via configuration files and includes utility functions for parsing arbitrary strings into argv[] arrays using shell-like rules.

Prerequisites

To cross compile the POPT command line utility, you need either a cross compiler, or an emulated Linux running on top of a virtualization software such as QEMU, matching your specific target platform.

If you wish to build yourself such a cross compiler, you should read the crosstool tutorial. There you will find all the information you need in order to build a C, C++ 4.1 GNU compiler for an ARM platform.

If you prefer to setup an ARM Debian system on top of a traditional Ubuntun distro (after all you are an hacker, aren't you?), have a look at How to setup an ARM Debian on Ubuntu tutorial in this wiki.

To cross compile the POPT command line utility, it is necessary to install the gettext package on your system. On Ubuntu or Debian linux systems, this can be done by typing the following command:

apt-get install gettext

Cross compilation process

Using a cross compiler

Assumptions

During the process, we will assume the cross toolchain is called xxx-yyy-linux-gnu, meaning that the gcc, g++, ar, ..., ld utilities are prefixed by xxx-yyy-linux-gnu.
For example, for this toolchain the C compiler is called xxx-yyy-linux-gnu-gcc.

We will also assume that the bin, include, lib and libexec folders of the cross toolchain are accessible through the PATH variable environment in order to work with the compilers from any place in the file system.

Finally, we assume that it is intalled in the following folder: /opt/crosstool/gcc-4.1.2-glibc-2.3.2/xxx-yyy-linux-gnu.

Organization

As mentioned above, the release being cross compiled is 1.10.4. The tar.gz file will then be extracted under the /opt/external_packages/popt/1.10.4/source folder and the results of the compilation will be stored under the /opt/external_packages/expat/1.10.4/compiled/xxx-yyy-linux-gnu folder.

The files resulting from the cross compilation are listed here:

.:
total 16
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 include
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 lib
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 man
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 share

./include:
total 16
-rw-r--r-- 1 root root 16238 2008-02-07 16:07 popt.h

./lib:
total 184
-rw-r--r-- 1 root root 97084 2008-02-07 16:07 libpopt.a
-rwxr-xr-x 1 root root   841 2008-02-07 16:07 libpopt.la
lrwxrwxrwx 1 root root    16 2008-02-07 16:07 libpopt.so -> libpopt.so.0.0.0
lrwxrwxrwx 1 root root    16 2008-02-07 16:07 libpopt.so.0 -> libpopt.so.0.0.0
-rwxr-xr-x 1 root root 76178 2008-02-07 16:07 libpopt.so.0.0.0

./man:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 man3

./man/man3:
total 32
-rw-r--r-- 1 root root 31011 2008-02-07 16:07 popt.3

./share:
total 4
drwxr-xr-x 32 root root 4096 2008-02-07 16:07 locale

./share/locale:
total 120
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 cs
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 da
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 de
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 es
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 eu_ES
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 fi
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 fr
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 gl
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 hu
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 id
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 is
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 it
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 ja
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 ko
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 no
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 pl
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 pt
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 pt_BR
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 ro
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 ru
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 sk
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 sl
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 sr
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 sv
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 tr
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 uk
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 wa
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 zh
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 zh_CN
drwxr-xr-x 3 root root 4096 2008-02-07 16:07 zh_TW

./share/locale/cs:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/cs/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1829 2008-02-07 16:07 popt.mo

./share/locale/da:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/da/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1622 2008-02-07 16:07 popt.mo

./share/locale/de:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/de/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/es:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/es/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1614 2008-02-07 16:07 popt.mo

./share/locale/eu_ES:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/eu_ES/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/fi:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/fi/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/fr:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/fr/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1952 2008-02-07 16:07 popt.mo

./share/locale/gl:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/gl/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1659 2008-02-07 16:07 popt.mo

./share/locale/hu:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/hu/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 519 2008-02-07 16:07 popt.mo

./share/locale/id:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/id/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/is:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/is/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1816 2008-02-07 16:07 popt.mo

./share/locale/it:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/it/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/ja:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/ja/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/ko:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/ko/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1939 2008-02-07 16:07 popt.mo

./share/locale/no:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/no/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1823 2008-02-07 16:07 popt.mo

./share/locale/pl:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/pl/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1852 2008-02-07 16:07 popt.mo

./share/locale/pt:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/pt/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1893 2008-02-07 16:07 popt.mo

./share/locale/pt_BR:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/pt_BR/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/ro:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/ro/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1173 2008-02-07 16:07 popt.mo

./share/locale/ru:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/ru/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1978 2008-02-07 16:07 popt.mo

./share/locale/sk:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/sk/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 533 2008-02-07 16:07 popt.mo

./share/locale/sl:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/sl/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 537 2008-02-07 16:07 popt.mo

./share/locale/sr:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/sr/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/sv:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/sv/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1867 2008-02-07 16:07 popt.mo

./share/locale/tr:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/tr/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1624 2008-02-07 16:07 popt.mo

./share/locale/uk:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/uk/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 527 2008-02-07 16:07 popt.mo

./share/locale/wa:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/wa/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 540 2008-02-07 16:07 popt.mo

./share/locale/zh:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/zh/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 366 2008-02-07 16:07 popt.mo

./share/locale/zh_CN:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/zh_CN/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1747 2008-02-07 16:07 popt.mo

./share/locale/zh_TW:
total 4
drwxr-xr-x 2 root root 4096 2008-02-07 16:07 LC_MESSAGES

./share/locale/zh_TW/LC_MESSAGES:
total 4
-rw-r--r-- 1 root root 1783 2008-02-07 16:07 popt.mo

Cross compilation

Step 1

Install the POPT command line utility software by untaring it in the /opt/external_packages/popt/1.10.4/source folder and then cd to this directory.

Note: All the below directories and files must be moved from the popt-1.10.4 folder to the parent folder (/opt/external_packages/popt/1.10.4/source)

ABOUT-NLS       config.guess  COPYING      install-sh    Makefile.in    popt.c        poptparse.c  test1.c     test-poptrc
aclocal.m4      config.h.in   depcomp      intl          missing        poptconfig.c  popt.ps      test2.c
autogen.sh      config.sub    Doxyfile.in  libpopt.vers  mkinstalldirs  popt.h        popt.spec    test3.c
autom4te.cache  configure     findme.c     ltmain.sh     po             popthelp.c    README       test3-data
CHANGES         configure.ac  findme.h     Makefile.am   popt.3         poptint.h     system.h     testit.sh

Step 2

We want to cross compile expat with its default parameters then we configure it by typing:

./configure --host=xxx-yyy-linux-gnu --prefix=/opt/external_packages/popt/1.10.4/compiled/xxx-yyy-linux-gnu

Step 3

To compile and install popt, type successively make and make install. You should find the directories and files listed above under /opt/external_packages/popt/1.10.4/compiled/xxx-yyy-linux-gnu.

Other cross compilation

You might be interested in cross compiling latest releases of popt such as popt 1.13. If this the case, the configure process might be stopped because of such errors:

checking for string.h... (cached) yes
checking for va_copy() function... configure: error: cannot run test program while cross compiling

Or

configure: error: no working implementation found

If this is case, please try the popt-1.13-configure file instead (rename as configure).

With QEMU

This section is not yet available.

Download

  • arm-popt-1.13-tar.gz
  • arm-popt-1.10.4-tar.gz
  • popt-1.13-configure

You may consult this section if you want to download the POPT command line utility already cross compiled for your target platform if it is available. You can also contribute to expand the crosscompile.org community by uploading your own results in the case a given platform is not already supported.

Supported platforms

  • arm-unknown-linux-gnu


Written by David Sayada.

Edit History Last Modified March 10, 2008