Skip to end of metadata
Go to start of metadata

Previously, we discussed how to add the basic APRE library in the "How to make a basic Makefile" chapter. This chapter describes the library and compile options that must be additionally described in Makefile in the environment in which the AIX xlc compiler is used.

Library and compile options for APRE compile in AIX environment

Library to be added to Makefile

As previously explained, the basic APRE library "-lapr -lodbccli" should be described in Makefile.

When compiling only with the basic library added, there are system libraries referenced by the APRE library and a reference error occurs. Therefore, system libraries used in APRE must be specified in Makefile as follows.

Library typeMakefile added library nameDescription
Thread library-lpthreadsThread library for POSIX thread function
Math related library-lmLibrary for using math function
C++ library-lCAdd when compiling using the C compiler in version 5.3.3 or earlier

Compile Options

It is necessary to specify the following options to improve performance and specify the compile bit type.

OptionOption displayDescription
Option to specify the maximum memory segment size-bmaxdataWhen compiling a 32bit program, specify the maximum usable memory segment size (default 256M)
Option to specify the 32bit/64 compile mode-q32When compiling a 32bit program
-q64When compiling a 64bit program
Compiler optimizzation mode-O2Using the Compiler Optimization Level 2
Option to use inline function-qinlineEnable inline function instead of the function call to improve the performance
Option for runtime linking-brtlOption for runtime linking, set when using a shared library
Option for symbol export-bexpallOption to export the global symbol when creating a shared library

By referring to the $ALTIBASE_HOME/install/ file and $ALTIBASE_HOME/sample/APRE/Makefile, it can be referred to the optimized compile and link options when compiling APRE.

Example of simple Makefile

The simplest Makefile that can compile ARE in AIX xlc environment is completed as follows. In addition, if there is an additional library referenced by the program, the library must be additionally described in Makefile.

LIBS=-lapre -lodbccli -lpthreads -lm
LFLAGS=-O2 -qinline -q64 #64bit compile mode

$(ALTIBASE_HOME)/bin/apre -t c


cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)


rm *.c *.o


Example of Makefile for 32-bit compile

An example of Makefile for 32bit compile is as follows. Specify "-q32" as a compile option, and specify the path where 32bit APRE library is installed in the path referencing the Header file and Library. In addition, the APRE Precompiler also specifies the path to execute 32bit APRE. If necessary, increase the memory segment to be used in the program, such as "-bmaxdata:0x80000000". In case of "bmaxdata:0x80000000", it can be used up to 2G.

LIBS=-lapre -lodbccli -lpthreads -lm
LFLAGS= -O2 -qinline -q32 -bmaxdata:0x80000000 -L. #32bit compile mode, setting the maximum memory segement size

/alticlient32/bin/apre -t c


cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)


rm *.c *.o

Example of Makefile using APRE Shared Library(

In $ALTIBASE_HOME/library, there are and provided in the form of shared library in addition to libapre.a, which is a static library.

Using a shared library has the following advantages compared to using a static library:

  • Can reduce the size of the executable file.
  • After loading the library into memory, it can be shared, reducing the memory usage of the program
  • When the used library is changed, only the library needs to be replaced and there is no need to recompile the executable file.

The following is an example of Makefile using a shared library using the xlc compiler in AIX. To use runtime linking, "brtl" was added as a link option and APRE shared library was added as a library.

LIBS=-lapre_sl -lodbccli_sl -lc -lpthreads -lm
LFLAGS=-O2 -brtl -qinline -q64 #64bit compile mode

$(ALTIBASE_HOME)/bin/apre -t c


cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)


rm *.c *.o

Example of Makefile for Shared library build using APRE source

If necessary, there is a case that a shared library consisting of a function that searches DB with APRE must be created and used by calling it from a program. The example below is an example of Makefile for creating a shared library with APRE.

First, write a C source for creating a library as follows.

Makefile for creating, which is to be used by calling the program using, is as follows.

Example of Makefile for shared library build


LIBS= -lc -lpthreads -lm # -lapre_sl -lodbccli_sl must be linked when building an executable file.
LFLAGS=-O2 -lc -q64 #64bit compile mode

all: $(SHLLIB)


xlc_r -G -o $(SHLLIB) $(OBJS) -b64 -bexpall -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)


xlc_r $(LFLAGS) -c connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)

$(ALTIBASE_HOME)/bin/apre -t c


rm *.o

Example of Makefile that compiles the program used by calling Shared Library made with APRE function

First, create "alticonn.h" as a header file for APRE shared library.


The user program is used by calling contest_db() registered in The source of the user program is as follows.


Example of Makefile for Execution Program Build

The Makefile to compile the user program used by calling contest_db() function registered in is as follows.


LIBS=-lapre_sl -lodbccli_sl -lc -lpthreads -lm
LFLAGS=-O2 -brtl -qinline -q64 #64bit compile mode




xlc_r $(LFLAGS) -o test test.c $(INC_ALL) $(LIB_ALL) -lconn_sl $(LIBS)


rm *.c *.o

Considerations when building shared library


In AIX, when creating and using more than one shared library, do not add -lapre_sl and -lodbccl_sl when building a shared library.

In the shared library of AIX, the global variables in the apre_sl and odbccli_sl libraries are recognized as different variables, so shared libraries cannot be shared. Therefore, when creating a shared library, do not link the APRE libraries (apre_sl, odbccli_sl), but link the APRE library when creating the executable binary.

For example, if the connection-related shared library is and the select-related shared library is, and binary is built and executed, an error occurs because cannot refer to connection-related object in To prevent this error, apre_sl and odbccli_sl should be added as links only when creating an executable binary.


  • No labels