iODBC SDK Development

Linking iODBC and ODBC Applications on Mac OS X

iODBC for Mac OS X ships as a Macintosh Installer package (.mpkg) inside a disk-image (.dmg) file. Double-click the disk image to mount it; then double-click the Macintosh Installer package. You will be guided through the rest of the installation by Installer.app.

iODBC follows the Programmer and System guidelines defined by Apple. This documentation can be found at developer.apple.com.

You will find the iODBC SDK installation in the following directory structure on Mac OS X:

Figure 1: iODBC SDK tree on Mac OS X


In Mac OS X, "frameworks" are the central components of all SDKs. They provide include files, shared libraries, and anything else needed by developers to link an application. All frameworks support is well managed with Apple's Project Builder. Simply use the GUI to drag and drop the framework that you want use. If you want to use frameworks via the command line compiler, see below.

The framework is basically a directory with the following structure:

Figure 2: iODBC SDK Frameworks on Mac OS X


When you need to include one of the framework header files, you have to prepend your header file name with the framework name. For example:

#include <samples/my_sample_header.h>


iODBC comprises three frameworks, each having its own proper set of includes files and libraries:

The iODBC SDK also ships with the iodbctest sample application including its sources and project file. iodbctest uses iODBC for data access.

First of all, you have to be sure that the compiler and linker you are using can manage frameworks correctly. Xcode does.

Under Project Builder, you must put all the frameworks that your application will use into your project. Implicitly, all these frameworks will be used. Also, you have to be sure that the machine where the application will be running includes all the frameworks with which you are linking. In certain cases, iODBC can be shipped with your application and all the frameworks.

This is the most straightforward way to proceed, but you can also directly use the compiler and command line linker shipped with Project Builder. In such a case, you will have to add certain options to let the compiler and linker know that you want to use a specific framework. However, the sources do not require any changes. During the compilation phase, you will have to use the "-F" option to add a path to enable the compiler to locate frameworks. The correct syntax is "-Fdir", where "dir" is the path that you want to add. You may only pass one path to each -F argument, but there is no limit to the number of -F arguments that you can pass on the command line. For iODBC, you have to add only the following two directories:

/Library/Frameworks
/System/Library/Frameworks


A complete cc compilation command line may look like this:

cc -c "-F/Library/Frameworks" "-F/System/Library/Frameworks" mysources.c


During the linkage phase, you will have to use the same option as above, as well as specify at the end of the command line all the frameworks with which you are linking, preceded by the option -framework.

A complete cc linkage command line may look like this:

cc -o "myapplication" "-F/Library/Frameworks" "-F/System/Library/Frameworks"  \
      -framework "iODBC" -framework "iODBCinst" -framework "iODBCadm"