How to Cross Compile unixODBC a Step by Step Guide

Introduction

This tutorial will show how to cross compile the unixODBC project on an GNU Linux embedded platform.

Overview of the project

The unixODBC project goals are to develop and promote unixODBC to be the definitive standard for ODBC on non MS Windows platforms. This is to include GUI support for both KDE and GNOME.

To find out more about the unixODBC project and its components see the project's website http://www.unixodbc.org.

Download

The unixODBC project releases can be found at: http://www.unixodbc.org/download.html.

The latest available release by the time of writing of this tutorial is 2.2.12 (October 13th 2006).

To download this release, just type the following command:

wget http://www.unixodbc.org/unixODBC-2.2.12.tar.gz

Environment Setup

The host machine will be a PC with a GNU Linux distribution installed.
The embedded platform might be constructed on top of one of the following architectures:

  • arm.
  • mips.
  • mipsel.
  • ppc.
  • sparc.

Prerequisites

To cross compile the unixODBC project, you need either a cross compiler, or an emulated Linux running on top of a virtualization software such as QEMU, matching your specific targeted platform.

In order to build yourself such a cross compiler, at crosstool page we introduced the way to build a C,C++ 4.1 GNU compiler for an ARM platform.

Also, hackers will be interested finding all the details to setup an ARM Debian system on their traditional Ubuntun distro following the indications quoted in this other arm-debian-on-ubuntu.

The unixODBC project does not need any specific dependencies.

The Cross compilation process

Option 1: 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 suppose 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: 2.2.12
  • The tar.gz file will then be extracted under: /opt/external_packages/unixODBC/2.2.12/source
  • The results of the compilation will be stored under: /opt/external_packages/unixODBC/2.2.12/compiled/xxx-yyy-linux-gnu

The files resulting from the cross compilation are listed here:

.:
total 16
drwxr-xr-x 2 root root 4096 2008-03-09 13:46 bin
drwxr-xr-x 3 root root 4096 2008-03-09 13:46 etc
drwxr-xr-x 2 root root 4096 2008-03-09 13:46 include
drwxr-xr-x 2 root root 4096 2008-03-09 13:46 lib

./bin:
total 240
-rwxr-xr-x 1 root root 69055 2008-03-09 13:46 dltest
-rwxr-xr-x 1 root root 35136 2008-03-09 13:46 isql
-rwxr-xr-x 1 root root 39526 2008-03-09 13:46 iusql
-rwxr-xr-x 1 root root 11946 2008-03-09 13:46 odbc_config
-rwxr-xr-x 1 root root 76670 2008-03-09 13:46 odbcinst

./etc:
total 4
drwxr-xr-x 2 root root 4096 2008-03-09 13:46 ODBCDataSources
-rw-r--r-- 1 root root    0 2008-03-09 13:46 odbc.ini
-rw-r--r-- 1 root root    0 2008-03-09 13:46 odbcinst.ini

./etc/ODBCDataSources:
total 0

./include:
total 196
-rw-r--r-- 1 root root  5511 2008-03-09 13:46 autotest.h
-rw-r--r-- 1 root root 10276 2008-03-09 13:46 odbcinstext.h
-rw-r--r-- 1 root root 16383 2008-03-09 13:46 odbcinst.h
-rw-r--r-- 1 root root 78462 2008-03-09 13:46 sqlext.h
-rw-r--r-- 1 root root 31945 2008-03-09 13:46 sql.h
-rw-r--r-- 1 root root 11202 2008-03-09 13:46 sqltypes.h
-rw-r--r-- 1 root root 21671 2008-03-09 13:46 sqlucode.h
-rw-r--r-- 1 root root  2302 2008-03-09 13:46 uodbc_extras.h
-rw-r--r-- 1 root root  2591 2008-03-09 13:46 uodbc_stats.h

./lib:
total 15712
-rw-r--r-- 1 root root   69130 2008-03-09 13:46 libboundparam.a
-rwxr-xr-x 1 root root     950 2008-03-09 13:46 libboundparam.la
lrwxrwxrwx 1 root root      22 2008-03-09 13:46 libboundparam.so -> libboundparam.so.1.0.0
lrwxrwxrwx 1 root root      22 2008-03-09 13:46 libboundparam.so.1 -> libboundparam.so.1.0.0
-rwxr-xr-x 1 root root   57574 2008-03-09 13:46 libboundparam.so.1.0.0
-rw-r--r-- 1 root root    8560 2008-03-09 13:46 libesoobS.a
-rwxr-xr-x 1 root root     854 2008-03-09 13:46 libesoobS.la
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libesoobS.so -> libesoobS.so.1.0.0
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libesoobS.so.1 -> libesoobS.so.1.0.0
-rwxr-xr-x 1 root root   12377 2008-03-09 13:46 libesoobS.so.1.0.0
-rw-r--r-- 1 root root    7706 2008-03-09 13:46 libgtrtst.a
-rwxr-xr-x 1 root root     853 2008-03-09 13:46 libgtrtst.la
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libgtrtst.so -> libgtrtst.so.1.0.0
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libgtrtst.so.1 -> libgtrtst.so.1.0.0
-rwxr-xr-x 1 root root   11304 2008-03-09 13:46 libgtrtst.so.1.0.0
-rw-r--r-- 1 root root    9050 2008-03-09 13:46 libmimerS.a
-rwxr-xr-x 1 root root     854 2008-03-09 13:46 libmimerS.la
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libmimerS.so -> libmimerS.so.1.0.0
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libmimerS.so.1 -> libmimerS.so.1.0.0
-rwxr-xr-x 1 root root   12633 2008-03-09 13:46 libmimerS.so.1.0.0
-rw-r--r-- 1 root root  383174 2008-03-09 13:46 libnn.a
-rwxr-xr-x 1 root root     826 2008-03-09 13:46 libnn.la
lrwxrwxrwx 1 root root      14 2008-03-09 13:46 libnn.so -> libnn.so.1.0.0
lrwxrwxrwx 1 root root      14 2008-03-09 13:46 libnn.so.1 -> libnn.so.1.0.0
-rwxr-xr-x 1 root root  233676 2008-03-09 13:46 libnn.so.1.0.0
-rw-r--r-- 1 root root 2962442 2008-03-09 13:46 libodbc.a
-rw-r--r-- 1 root root 1034634 2008-03-09 13:46 libodbccr.a
-rwxr-xr-x 1 root root     853 2008-03-09 13:46 libodbccr.la
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libodbccr.so -> libodbccr.so.1.0.0
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libodbccr.so.1 -> libodbccr.so.1.0.0
-rwxr-xr-x 1 root root  483209 2008-03-09 13:46 libodbccr.so.1.0.0
-rw-r--r-- 1 root root    5610 2008-03-09 13:46 libodbcdrvcfg1S.a
-rwxr-xr-x 1 root root     896 2008-03-09 13:46 libodbcdrvcfg1S.la
lrwxrwxrwx 1 root root      24 2008-03-09 13:46 libodbcdrvcfg1S.so -> libodbcdrvcfg1S.so.1.0.0
lrwxrwxrwx 1 root root      24 2008-03-09 13:46 libodbcdrvcfg1S.so.1 -> libodbcdrvcfg1S.so.1.0.0
-rwxr-xr-x 1 root root    9947 2008-03-09 13:46 libodbcdrvcfg1S.so.1.0.0
-rw-r--r-- 1 root root    5086 2008-03-09 13:46 libodbcdrvcfg2S.a
-rwxr-xr-x 1 root root     896 2008-03-09 13:46 libodbcdrvcfg2S.la
lrwxrwxrwx 1 root root      24 2008-03-09 13:46 libodbcdrvcfg2S.so -> libodbcdrvcfg2S.so.1.0.0
lrwxrwxrwx 1 root root      24 2008-03-09 13:46 libodbcdrvcfg2S.so.1 -> libodbcdrvcfg2S.so.1.0.0
-rwxr-xr-x 1 root root    9573 2008-03-09 13:46 libodbcdrvcfg2S.so.1.0.0
-rw-r--r-- 1 root root  750900 2008-03-09 13:46 libodbcinst.a
-rwxr-xr-x 1 root root     872 2008-03-09 13:46 libodbcinst.la
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libodbcinst.so -> libodbcinst.so.1.0.0
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libodbcinst.so.1 -> libodbcinst.so.1.0.0
-rwxr-xr-x 1 root root  387115 2008-03-09 13:46 libodbcinst.so.1.0.0
-rwxr-xr-x 1 root root     844 2008-03-09 13:46 libodbc.la
-rw-r--r-- 1 root root    5930 2008-03-09 13:46 libodbcminiS.a
-rwxr-xr-x 1 root root     875 2008-03-09 13:46 libodbcminiS.la
lrwxrwxrwx 1 root root      21 2008-03-09 13:46 libodbcminiS.so -> libodbcminiS.so.1.0.0
lrwxrwxrwx 1 root root      21 2008-03-09 13:46 libodbcminiS.so.1 -> libodbcminiS.so.1.0.0
-rwxr-xr-x 1 root root   10280 2008-03-09 13:46 libodbcminiS.so.1.0.0
-rw-r--r-- 1 root root    9514 2008-03-09 13:46 libodbcmyS.a
-rwxr-xr-x 1 root root     861 2008-03-09 13:46 libodbcmyS.la
lrwxrwxrwx 1 root root      19 2008-03-09 13:46 libodbcmyS.so -> libodbcmyS.so.1.0.0
lrwxrwxrwx 1 root root      19 2008-03-09 13:46 libodbcmyS.so.1 -> libodbcmyS.so.1.0.0
-rwxr-xr-x 1 root root   13289 2008-03-09 13:46 libodbcmyS.so.1.0.0
-rw-r--r-- 1 root root    5330 2008-03-09 13:46 libodbcnnS.a
-rwxr-xr-x 1 root root     861 2008-03-09 13:46 libodbcnnS.la
lrwxrwxrwx 1 root root      19 2008-03-09 13:46 libodbcnnS.so -> libodbcnnS.so.1.0.0
lrwxrwxrwx 1 root root      19 2008-03-09 13:46 libodbcnnS.so.1 -> libodbcnnS.so.1.0.0
-rwxr-xr-x 1 root root    9740 2008-03-09 13:46 libodbcnnS.so.1.0.0
-rw-r--r-- 1 root root 1343912 2008-03-09 13:46 libodbcpsql.a
-rwxr-xr-x 1 root root     891 2008-03-09 13:46 libodbcpsql.la
-rw-r--r-- 1 root root    8294 2008-03-09 13:46 libodbcpsqlS.a
-rwxr-xr-x 1 root root     875 2008-03-09 13:46 libodbcpsqlS.la
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libodbcpsql.so -> libodbcpsql.so.2.0.0
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libodbcpsql.so.1 -> libodbcpsql.so.1.0.0
-rwxr-xr-x 1 root root  754905 2008-03-09 13:46 libodbcpsql.so.1.0.0
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libodbcpsql.so.2 -> libodbcpsql.so.2.0.0
-rwxr-xr-x 1 root root  787134 2008-03-09 13:46 libodbcpsql.so.2.0.0
lrwxrwxrwx 1 root root      21 2008-03-09 13:46 libodbcpsqlS.so -> libodbcpsqlS.so.1.0.0
lrwxrwxrwx 1 root root      21 2008-03-09 13:46 libodbcpsqlS.so.1 -> libodbcpsqlS.so.1.0.0
-rwxr-xr-x 1 root root   12219 2008-03-09 13:46 libodbcpsqlS.so.1.0.0
lrwxrwxrwx 1 root root      16 2008-03-09 13:46 libodbc.so -> libodbc.so.1.0.0
lrwxrwxrwx 1 root root      16 2008-03-09 13:46 libodbc.so.1 -> libodbc.so.1.0.0
-rwxr-xr-x 1 root root 1582782 2008-03-09 13:46 libodbc.so.1.0.0
-rw-r--r-- 1 root root 1840778 2008-03-09 13:46 libodbctxt.a
-rwxr-xr-x 1 root root     866 2008-03-09 13:46 libodbctxt.la
-rw-r--r-- 1 root root    8022 2008-03-09 13:46 libodbctxtS.a
-rwxr-xr-x 1 root root     868 2008-03-09 13:46 libodbctxtS.la
lrwxrwxrwx 1 root root      19 2008-03-09 13:46 libodbctxt.so -> libodbctxt.so.1.0.0
lrwxrwxrwx 1 root root      19 2008-03-09 13:46 libodbctxt.so.1 -> libodbctxt.so.1.0.0
-rwxr-xr-x 1 root root  934724 2008-03-09 13:46 libodbctxt.so.1.0.0
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libodbctxtS.so -> libodbctxtS.so.1.0.0
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libodbctxtS.so.1 -> libodbctxtS.so.1.0.0
-rwxr-xr-x 1 root root   11895 2008-03-09 13:46 libodbctxtS.so.1.0.0
-rw-r--r-- 1 root root    9034 2008-03-09 13:46 liboplodbcS.a
-rwxr-xr-x 1 root root     868 2008-03-09 13:46 liboplodbcS.la
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 liboplodbcS.so -> liboplodbcS.so.1.0.0
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 liboplodbcS.so.1 -> liboplodbcS.so.1.0.0
-rwxr-xr-x 1 root root   13003 2008-03-09 13:46 liboplodbcS.so.1.0.0
-rw-r--r-- 1 root root    6314 2008-03-09 13:46 liboraodbcS.a
-rwxr-xr-x 1 root root     868 2008-03-09 13:46 liboraodbcS.la
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 liboraodbcS.so -> liboraodbcS.so.1.0.0
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 liboraodbcS.so.1 -> liboraodbcS.so.1.0.0
-rwxr-xr-x 1 root root   10614 2008-03-09 13:46 liboraodbcS.so.1.0.0
-rw-r--r-- 1 root root    6322 2008-03-09 13:46 libsapdbS.a
-rwxr-xr-x 1 root root     854 2008-03-09 13:46 libsapdbS.la
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libsapdbS.so -> libsapdbS.so.1.0.0
lrwxrwxrwx 1 root root      18 2008-03-09 13:46 libsapdbS.so.1 -> libsapdbS.so.1.0.0
-rwxr-xr-x 1 root root   10567 2008-03-09 13:46 libsapdbS.so.1.0.0
-rw-r--r-- 1 root root    7418 2008-03-09 13:46 libtdsS.a
-rwxr-xr-x 1 root root     840 2008-03-09 13:46 libtdsS.la
lrwxrwxrwx 1 root root      16 2008-03-09 13:46 libtdsS.so -> libtdsS.so.1.0.0
lrwxrwxrwx 1 root root      16 2008-03-09 13:46 libtdsS.so.1 -> libtdsS.so.1.0.0
-rwxr-xr-x 1 root root   11418 2008-03-09 13:46 libtdsS.so.1.0.0
-rw-r--r-- 1 root root 1308358 2008-03-09 13:46 libtemplate.a
-rwxr-xr-x 1 root root     872 2008-03-09 13:46 libtemplate.la
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libtemplate.so -> libtemplate.so.1.0.0
lrwxrwxrwx 1 root root      20 2008-03-09 13:46 libtemplate.so.1 -> libtemplate.so.1.0.0
-rwxr-xr-x 1 root root  649733 2008-03-09 13:46 libtemplate.so.1.0.0

Cross Compiling

Step 1

Install the unixODBC project by untaring it in /opt/external_packages/unixODBC/2.2.12/source folder and then cd to this directory.

Note:
All the directories and files listed below must be moved from the unixODBC-2.2.12 folder
to its parent folder (/opt/external_packages/unixODBC/2.2.12/source).

Directories and files:

   acinclude.m4  configure      depcomp        gODBCConfig  log            NEWS        README.AIX      samples
   aclocal.m4    configure.in   doc            include      lst            ODBCConfig  README.GTK      sqp
   AUTHORS       contrib        DriverManager  ini          ltmain.sh      odbcinst    README.INTERIX  unixODBC.spec
   autotest      COPYING        Drivers        INSTALL      Makefile.am    odbcinstQ   README.OSX      unixODBC-sr.spec
   ChangeLog     cur            DRVConfig      install-sh   Makefile.in    odbctest    README.QNX      vms
   config.guess  DataManager    exe            Interix      missing        qt.m4       README.SOLARIS  vmsbuild.com
   config.sub    DataManagerII  extras         libltdl      mkinstalldirs  README      README.VMS
   

Step 2

We want to cross compile unixODBC with the following options:

  • build both static and shared libraries
  • build GUI parts disabled
  • gnu threads support disabled
  • readline support enabled
  • ini file caching support enabled
  • included drivers enabled
  • file-based data access disabled
  • no use of relaxed handle checking in the DM
  • iconv support enabled
  • statistic gathering support enabled
  • RTLD_GROUP passed to dlopen enabled
  • using of libltdl.so disabled
Step 3

We configure the software, according to the previous options, by typing the following command:

./configure --host=xxx-yyy-linux-gnu --prefix=/opt/external_packages/unixODBC/2.2.12/compiled/xxx-yyy-linux-gnu --disable-gui --enable-static
Step 4

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

Option 2: Using QEMU

This section is not yet available.

Download

  • arm-unixODBC-2.2.12-tar.gz

You may consult this section if you want to download the unixODBC project 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