Compiling and Linking Applications

There are methods for compiling and linking C applications on Windows and on Linux or UNIX.

Compiling and Linking Applications on Windows

There are methods for how to compile TimesTen applications on Windows. You are not required to specify the location of the ODBC include files. These files are included with Microsoft Visual C++. However, to use TimesTen features you must indicate the location of the TimesTen include files in the /I compiler option setting.

See TimesTen Include Files.

Link the appropriate libraries, as follows:

  • Link directly to the native Windows driver manager, odbc32.lib

  • Or link directly to one of the TimesTen drivers:

    • For direct mode: tten221.lib and ttdv221.lib

    • For client/server mode: ttclient221.lib

Link TimesTen libraries before any other libraries.

In addition, applications must do the following:

  • Include timesten.h, the TimesTen include file. This automatically includes standard ODBC files as well. See TimesTen Include Files.

  • Include TimesTen files before any other include files.

The Makefile in this example shows how to build a TimesTen application on Windows systems. This example assumes that timesten_home\install\lib has already been added to the LIB environment variable (which is accomplished when you execute ttenv.bat).

CFLAGS = "/Itimesten_home\install\include"
LIBSDM = ODBC32.LIB
LIBS = tten221.lib ttdv221.lib
LIBSDEBUG = tten221d.lib ttdv221d.lib
LIBSCS = ttclient221.lib

# Link with the ODBC driver manager
appldm.exe:appl.obj
           $(CC) /Feappldm.exe appl.obj $(LIBSDM)

# Link directly with the TimesTen
# ODBC production driver
appl.exe:appl.obj
         $(CC) /Feappl.exe appl.obj\
         $(LIBS)

# Link directly with the TimesTen
# ODBC debug driver
appldebug.exe:appl.obj
              $(CC) /Feappldebug.exe appl.obj\
              $(LIBSDEBUG)

# Link directly with the TimesTen
# ODBC client driver
applcs.exe:appl.obj
           $(CC) /Feapplcs.exe appl.obj\
           $(LIBSCS)

Note:

  • TimesTen defaults to ODBC 3.5. To use ODBC 2.5 definitions and types, use the compiler setting -DODBCVER=0x0250.

  • On Windows, there is only one TimesTen instance per installation, and timesten_home refers to installation_dir\instance.

  • The timesten_home\install directory is a symbolic link to installation_dir.

Compiling and Linking Applications Directly With the TimesTen Drivers on Linux or UNIX

There are methods on how to compile TimesTen applications directly with the TimesTen drivers on Linux or UNIX platforms.

  • Compile TimesTen applications using the TimesTen header files in the include directory of the TimesTen installation.

  • Link with the TimesTen direct driver or the TimesTen client driver, each of which is provided as a shared library.

  • Link TimesTen libraries before any other libraries.

In addition, applications must do the following:

  • Include timesten.h, the TimesTen include file. This automatically includes standard ODBC files as well. See TimesTen Include Files.

  • Include TimesTen files before any other include files.

To use the TimesTen include files if you are using TimesTen features, add the following to the C compiler command.

-Itimesten_home/install/include

To link with the TimesTen ODBC direct driver, add the following to the link command for the libtten.so library:

-Ltimesten_home/install/lib -ltten

The -L option tells the linker to search the TimesTen lib directory for library files. The -ltten option links in the TimesTen ODBC direct driver.

To link with the TimesTen ODBC client driver, add the following to the link command for the libttclient.so library:

-Ltimesten_home/install/lib -lttclient

On AIX, when linking applications with the TimesTen ODBC client driver, the C++ runtime library must be included in the link command (because the client driver is written in C++ and AIX does not link it automatically) and must follow the client driver:

-Ltimesten_home/install/lib -lttclient -lC_r

You do not have to include this library if you are linking with the TimesTen driver manager, discussed in Compiling and Linking Applications With the TimesTen Driver Manager on Linux or UNIX.

You can use Makefiles in subdirectories under the Quick Start sample_code directory (see About TimesTen Quick Start and Sample Applications), or you can use this example to guide you in creating your own Makefile.

CFLAGS = -Itimesten_home/install/include
LIBS = -Ltimesten_home/install/lib -ltten
LIBSDEBUG = -Ltimesten_home/install/lib -lttenD
LIBSCS = -Ltimesten_home/install/lib -lttclient

# Link directly with the TimesTen
# ODBC production driver
appl:appl.o
     $(CC) -o appl appl.o $(LIBS)

# Link directly with the TimesTen ODBC debug driver
appldebug:appl.o
     $(CC) -o appldebug appl.o $(LIBSDEBUG)

# Link directly with the TimesTen client driver
applcs:appl.o
     $(CC) -o applcs appl.o $(LIBSCS)

Note:

  • TimesTen compiles against ODBC 3.5 by default. To compile an ODBC 2.5 application, use the compilation option setting -DODBCVER=0x0250.

  • To directly link your application to the debug TimesTen ODBC driver, substitute -lttenD for -ltten on the link line.

Compiling and Linking Applications With the TimesTen Driver Manager on Linux or UNIX

This section discusses and shows commands for linking applications with the TimesTen driver manager (which is not supported on Windows).

With a few exceptions for specific discussion of the TimesTen direct and client/server drivers, discussion in the preceding section, Compiling and Linking Applications Directly With the TimesTen Drivers on Linux or UNIX, applies when you use TTDM, but note the following:

  • Include timesten.h as you would normally. In addition, include any other TimesTen header files that you would normally. If your application uses XLA, include tt_xla.h. If your application uses the TimesTen utility API, include tt_utillib.h and ttutil.h.

  • Link with the TTDM library, libttdrvmgr.so, instead of the ODBC direct driver or client/server driver. Do not link with any other TimesTen library.

  • Do not link with any third-party driver manager library.

For example:

-Ltimesten_home/install/lib -lttdrvmgr

In a Makefile:

CFLAGS = -Itimesten_home/install/include
LIBTTDM = -Ltimesten_home/install/lib -lttdrvmgr
# Link with TTDM
applcs:appl.o
     $(CC) -o applcs appl.o $(LIBTTDM)