Altibase Precompiler (APRE*C/C++) Makefile#
Overview#
This document describes how to compile using the APRE*C/C++ Precompiler provided by Altibase on the Unix system and how to solve problems that may occur at each stage of compilation.
Examples and descriptions used in this document were written in the Linux and GCC compilation environment, and additional information has been described so that other compiler users of other UNIX environments (HP, SUN, AIX) can refer to them.
It is recommended to refer to the following documents in advance.
The test environment of this document is as follows:
- ALTIBASE: Altibase 6 and later
- OS: Linux (2.6.32-504.el6.x86_64)
- Compiler version: gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
Info
For errors and improvements related to this document, please contact the technical support portal or technical support center.
- Technical support portal: http://support.altibase.com/en
- Technical support center: +82-2-2082-1114
Info
This document is provided for informational purposes only and is subject to change without prior notice. It may contain errors, and Altibase makes no express or implied warranties of any kind, including but not limited to warranties of merchantability or fitness for a particular purpose.
The development, release, and timing of any features or functionality described for Altibase products in this document are at the sole discretion of Altibase.
Altibase may hold patents, trademarks, copyrights, or other intellectual property rights related to the contents of this document.
How to make a basic Makefile#
To understand the structure of Makefile, let's take a look at how to make a Makefile with simple c code.
As the Altibase Makefile specification complies with the GNU specification, it is recommended to use gmake. However, in this document, it is explained according to the general rules regardless.
Basic structure of Makefile#
A Makefile is a scripting language that defines the processes that are going on to make an executable file.
Let's compile the following simple source.
#include
main()
{
printf (“hello, world\n”);
}
This source can be compiled at the prompt as follows.
$ cc –o a a.c
It can be compiled with make using the simple Makefile script as follows.
$ vi Makefile
a:a.c # User-created protocols and dependencies
cc -o a a.c # Describes the actual command line to be executed
$ make -f Makefile
- a:a.c : Look for a.c in order to build a (check whether it has changed)
- cc -o a a.c : executes this command when a.c exists
- make -f Makefile : If the file name is Makefile, -f Makefile can be omitted
As described above, a Makefile is a script file that defines the dependency relationships among source files and the commands to be executed in order to build a target.
If there is no change to the same source, the message "make: is up to date" will be output because compilation does not need to be performed.
Example Sources#
The example to proceed with uses $ALTIBASE_HOME/sample/APRE/connect1.sc, included in the sample directory of the installed Altibase. (Based on Altibase 5.3 or later)
This example was written based on the environment compiling based on the GCC compiler in Linux. Therefore, when using other Unix environments and compilers, a part of Makefile must be written differently for the environment.
Some of the sources are as follows.
$ vi connect1.sc
int main()
{
char usr[20];
char pwd[20];
char opt [200];
sprintf (usr, “sys”);
sprintf (pwd, “manager”);
sprintf (opt, “DSN=127.0.0.1;CONNTYPE=1;PORT_NO=27584”);
EXEC SQL CONNECT :usr IDENTIFIED BY :pwd USING :opt ;
if (sqlca.sqlcode != 0)
printf (“ConnectErr: %d-%s\n”, SQLCODE,sqlca.sqlerrm.sqlerrmc);
Running the Precompile#
The APRE extension of Altibase uses "*.sc". Since this file is not in a format that can be directly interpreted by the C/C++ compiler, it must be converted into C/C++ source with the precompiler provided by Altibase.
-
Makefile contents
connect1.sc:connect1.sc apre -t c connect1.sc -
Execution
$ make -f Makefile connect1.scAfter creating the Makefile like this and running it, you can confirm that connect1.c is newly created. (Depending on the extension option, it is generated as .c or .cpp.)
Compiling#
Now add a convention to the Makefile to make it the executable connect1.

Of course, it is okay to use pre-compilation protocols and compile conventions in the connect1 protocol. Here, it will be explained separately. In the above, because the connect1 protocol requires connect1.c in the make step, the protocol for connect1.c is found in the Makefile.
Since there is a corresponding protocol in the Makefile, it operates in the order of precompiling first and then cc compiling.
However, when actually compiling, it will get the following error.
$ make -f Makefile connect1
apre -t c connect1.sc
-----------------------------------------------------------------
Altibase C/C++ Precompiler.
Release Version 6.5.1.3.0
Copyright 2000, ALTIBASE Corporation or its subsidiaries.
All Rights Reserved.
-----------------------------------------------------------------
cc -o connect1 connect1.c
connect1.c:9:29: error: ulpLibInterface.h: No such file or directory
connect1.c: In function 'main':
connect1.c:68: error: storage size of 'ulpSqlstmt' isn't known
..........................................................
make: *** [connect1] Error 1
There was an error that the header file could not be found.
In the Makefile, the path to the header and library that the user used on the source to compile should be specified as described in the next step.
Specifying the header file and library path#
Modify Makefile as follows to refer to Header file and Library.
$ vi Makefile
ALTI_INCLUDE=${ALTIBASE_HOME}/include
ALTI_LIBRARY=${ALTIBASE_HOME}/lib
connect1.c: connect1.sc
apre –t c connect1.sc
connect1 : connect1.c
cc –o connect1 connect1.c –I$(ALTI_INCLUDE) –L$(ALTI_LIBRARY)
As with the ALTI_INCLUDE and ALTI_LIBRARY environment variables of a user account, this sets an environment variable that is only applicable within the Makefile, and adds it to the compile command line.
The execution result this time shows a different error from the one encountered earlier.
$ make connect1
apre -t c connect1.sc
cc -o connect1 connect1.c -I/altibase_home/include -L/ssd/altibase_home/lib
/tmp/ccREjTkg.o: In function `main':
connect1.c:(.text+0x13a): undefined reference to `ulpGetSqlca'
.............................................................................
.............................................................................
collect2: ld returned 1 exit status
make: *** [connect1] Error 1
The above error occurs when trying to refer to the library in which the functions used in the source are defined, but cannot be found at the compile stage.
In the case of headers, it is not necessary to specify all individual header files, but in the case of a library, it must be specified.
Specifying the basic library for APRE compilation#
Modify the Makefile as follows.
Add basic library for APRE
$ vi Makefile
ALTI_INCLUDE=${ALTIBASE_HOME}/include
ALTI_LIBRARY=${ALTIBASE_HOME}/lib -lapre -lodbccli
connect1.c:connect1.sc
apre -t c connect1.sc
connect1:connect1.c
cc -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY)
Altibase requires the apre and odbccli libraries when generating a binary through precompilation. These are located in $ALTIBASE_HOME/lib.
The notation for the library in the Makefile is specified with the "-l" option, and the corresponding file exists in the form of "libapre.a" or "libapre_sl.so". In the library name, the name can be specified without "lib" and the extension (.a or .so).
Adding the system library#
When checking the executed result after recompiling with only the basic library added, an error still occurs as follows.
$ make connect1
apre -t c connect1.sc
cc -o connect1 connect1.c -I/ssd/altibase_home/include -L/ssd/altibase_home/lib -lapre -lodbccli
/ssd/altibase_home/lib/libapre.a(ulpLibInterface.o): In function `ulpLibInit':
ulpLibInterface.c:(.text+0x77): undefined reference to `pthread_rwlock_init'
/ssd/altibase_home/lib/libapre.a(ulpLibInterface.o): In function `ulpDoEmsql':
ulpLibInterface.c:(.text+0x1e6): undefined reference to `pthread_rwlock_wrlock'
...........................................
...........................................
The above error message occurs because the thread library for the POSIX thread function used within the APRE library cannot be found.
As with the previously added library, other libraries referenced by APRE must also be added to the Makefile.
$ vi Makefile
ALTI_INCLUDE=${ALTIBASE_HOME}/include
ALTI_LIBRARY=${ALTIBASE_HOME}/lib -lapre -lodbccli -lpthread
connect1.c:connect1.sc
apre -t c connect1.sc
connect1:connect1.c
cc -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY)
Additional system libraries required for compilation and each compilation option differ depending on the OS environment and the type of compiler. For more detailed information, please refer to the description of each compiler in this document.
After checking the list of system libraries required when compiling apre by using one of the methods below, the library can be added to Makefile.
- How to refer to Altibase's sample Makefile
- How to use the ldd command
- How to use the nm command
- How to refer to the man page
1. Referring to Altibase's Sample Makefile#
The list of libraries required for APRE compilation is available in $ALTIBASE_HOME/install/altibase_env.mk. After referring to it, each library and option can be specified in the user's Makefile.
2. Using the ldd Command#
The use of the ldd command is as follows.
$ ldd $ALTIBASE_HOME/bin/apre
linux-vdso.so.1 => (0x00007fff977ff000)
libdl.so.2 => /lib64/libdl.so.2 (0x000000369c200000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x000000369ca00000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00000036a9600000)
librt.so.1 => /lib64/librt.so.1 (0x000000369d600000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00000036a1600000)
libm.so.6 => /lib64/libm.so.6 (0x000000369ce00000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000369fe00000)
libc.so.6 => /lib64/libc.so.6 (0x000000369c600000)
/lib64/ld-linux-x86-64.so.2 (0x000000369be00000)
libfreebl3.so => /lib64/libfreebl3.so (0x00000036a9a00000)
3. Using the nm Command#
If the symbol that cannot be referenced during compilation is the "cos" function, you can run "nm -A /usr/lib/lib* | grep cos" as shown below to check, from the undefined symbol name, which library reference is required.
$ nm -A /usr/lib/lib* | grep cos ( cos is the undefined symbol name )
nm: /usr/lib/libc.so: File format not recognized
nm: /usr/lib/libfreebl3.chk: File format not recognized
nm: /usr/lib/libfreebl3.so: no symbols
/usr/lib/libm.so:00009480 t __acos
/usr/lib/libm.so:000105c0 t __acosf
/usr/lib/libm.so:00009510 t __acosh
/usr/lib/libm.so:00010640 t __acoshf
/usr/lib/libm.so:00017ec0 t __acoshl
/usr/lib/libm.so:00017e40 t __acosl
/usr/lib/libm.so:0000c140 t __cacos
/usr/lib/libm.so:00013050 t __cacosf
Since libm.so is referenced as above, add "-lm" to Makefile.
4. Using the man Page#
Using the UNIX man command, for some symbols you can find the symbol's purpose and the library it references using the following method.
$ man 3 cos ( cos is the undefined symbol name )
COS(3) Linux Programmer Manual COS(3)
NAME
cos, cosf, cosl - cosine function
SYNOPSIS
#include <math.h>
double cos(double x);
float cosf(float x);
long double cosl(long double x);
Link with -lm.
The man page explains that the cos function is included in the math-related library, and that the library "-lm" should be added when linking.
Causes and solutions for bit errors during compilation#
Using the APRE library suitable for compilation mode#
To create a 64bit program using APRE, you need a 64bit APRE compiler, 64bit APRE library and header files, and 64bit compilation options.
Similarly, to create a 32bit program, you must use a 32bit APRE compiler, 32bit APRE library and header files, and 32bit compilation options.
Note that if the DB server package is 64-bit, the 64-bit client development tools are included by default and installed along with the server. However, if you need to install the 64-bit development tools on a separate server, or if you require a 32-bit package, please request the appropriate client package for your current (or intended) Altibase version via http://support.altibase.com/en.
Bit error when compiling#
-
How to check the bit of the library
If the compile bit and the bit of the linked APRE library do not match, an error occurs during compilation. In this case, you need to check whether the corresponding library's bit is 32bit or 64bit. Check the bit of the library using the following method.
$ cd $ALTIBASE_HOME/lib # directory where the altibase apre library is installed $ file libapre_sl.so libapre_sl.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), dynamically linked, not stripped # when the 32bit APRE library is installed on Linux libapre_sl.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, not stripped # when the 64bit APRE library is installed on LinuxAs shown above, the bit of the library can be checked with the "file" command, which is a Unix command. The message may differ slightly by OS, but the bit can be inferred in the same way from the message.
-
Bit options when compiling
Bit-related compile options must be specified for each compiler.
The table below shows the 32bit and 64bit compile options for each compiler.
The options may vary depending on the CPU type supported by the compiler, so refer to the manual for each compiler for other detailed options.
OS SUN HP AIX Linux cc compiler 64bit option -xarch=v9 or "-m64 -xarch=sparc"
(when using SUN Sparc)+DD64 -q64 -m64 cc compiler 32bit option -xarch=v8plusa (when using SUN Sparc) +DD32 -q32 -m32
Adding C++ library#
Prior to Altibase 5.5.1, the APREC/C++ (SESC/C++) Precompiler included some C++ syntax elements.
Therefore, when compiling with a C compiler rather than a C++ compiler, a few compatible system libraries are needed in order to reference them in an interpretable form.
If the C++-related library is not included, an error that fails to find the C++-related operator occurs, as shown below.
Error Message Generated During make#
$ sesc -t c connect1.sc
-----------------------------------------------------------------
Altibase C/C++ Precompiler.
Release Version 5.3.3.38
Copyright 2000, ALTIBASE Corporation or its subsidiaries.
All Rights Reserved.
-----------------------------------------------------------------
gcc -o connect1 connect1.c -I/ssd/altibase_home/include -L/ssd/altibase_home/lib -lsesc -lodbccli -lpthread -lm -ldl -lcrypt -lrt
/ssd/altibase_home/lib/libodbccli.a(idvHandlerTimer_aoc.o): In function `idvTimerThread::~idvTimerThread()':
idvHandlerTimer.cpp:(.gnu.linkonce.t._ZN14idvTimerThreadD0Ev+0xc): undefined reference to `operator delete(void*)'
/ssd/altibase_home/lib/libodbccli.a(idvHandlerTimer_aoc.o):(.gnu.linkonce.r._ZTI14idvTimerThread+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
...............................
To resolve the error, you need to add the C++ standard library. In the case of the gcc compiler, add "-lstdc++" to the Makefile as follows.
$ vi Makefile
ALTI_INCLUDE=${ALTIBASE_HOME}/include
ALTI_LIBRARY=${ALTIBASE_HOME}/lib -lapre -lodbccli -lpthread -lstdc++
...............................
When using the C compiler, the C++ library required for each platform is as follows.
Please refer to the table below and add them to the Makefile for each compiler.
| Platform | Library |
|---|---|
| SUN | -lCrun |
| HP | -lstd –lstream –lCsup -lc |
| AIX | -lC |
| LINUX | -lstdc++ -lc |
Tip
Starting with Altibase 5.5.1, the APRE library was rewritten in C source code.
Therefore, even when compiling with a C compiler, there is no need to add a separate C++ library to the Makefile.
Using the C++ compiler#
In the case of using the C++ compiler, most of the problems listed above can be avoided, so it will not be explained separately.
However, the C++ compiler has a separate 64bit option, so be sure to familiarize yourself with this for each compiler.
Makefile for Linux gcc#
Previously, in "How to make a basic Makefile," we looked at how to add the basic APRE library.
This chapter describes the library and compile options that must be additionally described in the Makefile in the Linux gcc environment.
Additional library and compile options for APRE compilation in the Linux environment#
-
Library to be added to the Makefile
As already explained above, the basic APRE library "-lapre -lodbccli" must be described in the Makefile.
If you compile with only the basic library added, a reference error occurs because the system libraries referenced by APRE are missing.
Therefore, refer to the table below to specify the system libraries used by APRE in the Makefile.
Library type Makefile Library Description Posix thread library -lpthread Thread library for POSIX thread functions Math-related library -lm Library for using math functions Dynamic Linking Loader (DL) Library -ldl Dynamically loaded (DL) library C++ library -lstdc++ Specify the C++ library when compiling with gcc in Altibase 5.3.3 or earlier Realtime Extensions Library -lrt -
Compile options
The following options need to be specified to improve performance and specify the compile bit type.
Option name Option Description 32bit/64bit compile mode -m64 Generates 64-bit code -m32 Generates 32-bit code Info
By referring to the $ALTIBASE_HOME/install/altibase_env.mk file and $ALTIBASE_HOME/sample/APRE/Makefile, you can find the optimized compile and link options for compiling APRE.
-
Example of a simple Makefile
The simplest Makefile that can compile APRE in the Linux gcc environment is now complete, as shown below.
In addition, if there are additional libraries referenced by the program, they must also be described in the Makefile.
$ cat Makefile ALTI_INCLUDE=${ALTIBASE_HOME}/include ALTI_LIBRARY=${ALTIBASE_HOME}/lib -lapre -lodbccli SYS_LIBS=-lpthread -lm -ldl -lcrypt -lstdc++ -lrt connect1.c:connect1.sc apre -t c connect1.sc connect1:connect1.c cc -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(SYS_LIBS)
Example of Makefile for 32bit compile#
An example of an APRE Makefile for gcc that specifies the 32bit compile option is as follows.
Specify "-m32" as the compile option, and specify the path where the 32bit APRE library is installed in the path referencing the header file and library.
Also specify the path so that the 32bit APRE precompiler is executed.
ALTI_INCLUDE=/alticlient32/include
ALTI_LIBRARY=/alticlient32/lib -lapre -lodbccli
SYS_LIBS=-lpthread -lm -ldl -lc
connect1.c:connect1.sc
/alticlient32/bin/apre -t c connect1.sc
connect1:connect1.c
gcc -m32 -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(SYS_LIBS)
clean:
rm *.c *.o
Makefile for AIX xlc#
This chapter describes the library and compile options that must be additionally described in the Makefile in an environment that uses the AIX xlc compiler.
Library and compile options for APRE compilation in the AIX environment#
-
Library to be added to the Makefile
In addition to the basic APRE library "-lapre -lodbccli", refer to the table below to specify the system libraries used by APRE in the Makefile.
Library type Makefile added library name Description Thread library -lpthreads Thread library for POSIX thread functions Math-related library -lm Library for using math functions C++ library -lC Add when compiling with the C compiler in Altibase 5.3.3 or earlier -
Compile options
The following options need to be specified to improve performance and specify the compile bit type.
Option name Option Description Maximum memory segment size option -bmaxdata When compiling a 32bit program, specifies the maximum usable memory segment size (default 256M) 32bit/64bit compile mode designation -q32 When compiling a 32bit program -q64 When compiling a 64bit program Compiler optimization mode -O2 Uses compiler optimization level 2 Whether to use inline functions -qinline Sets the use of inline functions instead of function calls to improve performance Runtime linking option -brtl Option for runtime linking. Set when using a shared library Symbol export option -bexpall Setting to export global symbols when creating a shared library Info
By referring to the $ALTIBASE_HOME/install/altibase_env.mk file and $ALTIBASE_HOME/sample/APRE/Makefile, you can find the optimized compile and link options for compiling APRE.
-
Example of a simple Makefile
The simplest Makefile that can compile APRE in the AIX xlc environment is now complete, as shown below.
In addition, if there are additional libraries referenced by the program, they must also be described in the Makefile.
ALTI_INCLUDE=$(ALTIBASE_HOME)/include ALTI_LIBRARY=$(ALTIBASE_HOME)/lib LIBS=-lapre -lodbccli -lpthreads -lm LFLAGS=-O2 -qinline -q64 #64bit compile mode connect1.c:connect1.sc $(ALTIBASE_HOME)/bin/apre -t c connect1.sc connect1:connect1.c cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS) clean: rm *.c *.o
Example of Makefile for 32bit compile#
An example of a Makefile for 32bit compilation is as follows.
Specify "-q32" as the compile option, and specify the path where the 32bit APRE library is installed in the path referencing the header file and library.
Also specify the path so that the 32bit APRE precompiler is executed.
If necessary, increase the memory segment size used by the program, such as with "-bmaxdata:0x80000000". With "-bmaxdata:0x80000000", up to 2G can be used.
ALTI_INCLUDE=/alticlient32/include
ALTI_LIBRARY=/alticlient32/lib
LIBS=-lapre -lodbccli -lpthreads -lm
LFLAGS= -O2 -qinline -q32 -bmaxdata:0x80000000 -L. # 32bit compile mode, setting the maximum memory segment size
connect1.c:connect1.sc
/alticlient32/bin/apre -t c connect1.sc
connect1:connect1.c
cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)
clean:
rm *.c *.o
Example of Makefile using APRE Shared Library (libapre_sl.so)#
In $ALTIBASE_HOME/lib, in addition to the static library libapre.a, there are libapre_sl.so and libodbccli_sl.so, which are provided in the form of shared libraries.
Using a shared library has the following advantages compared to using a static library:
- The size of the executable file can be reduced.
- The library can be loaded into memory and shared, reducing the program's memory usage.
- When the library used 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 a Makefile using a shared library with the xlc compiler in AIX.
To use runtime linking, "-brtl" was added as a link option, and the APRE shared library was added as a library.
ALTI_INCLUDE=$(ALTIBASE_HOME)/include
ALTI_LIBRARY=$(ALTIBASE_HOME)/lib
LIBS=-lapre_sl -lodbccli_sl -lc -lpthreads -lm
LFLAGS=-O2 -brtl -qinline -q64 # 64bit compile mode
connect1.c:connect1.sc
$(ALTIBASE_HOME)/bin/apre -t c connect1.sc
connect1:connect1.c
cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)
clean:
rm *.c *.o
Example of Makefile for building a shared library from APRE source#
Depending on the need, there are cases where a shared library consisting of functions that query the DB through APRE must be created and used by calling it from a program.
The example below is an example of a Makefile for creating a shared library with APRE.
First, write the C source for creating the library as follows.
connect1.sc
/ connect1.sc /
int contest_db();
int contest_db()
{
/ declare host variables /
EXEC SQL BEGIN DECLARE SECTION;
char usr[10];
char pwd[10];
char conn_opt1[100];
char conn_opt2[100];
char conn_opt3[100];
EXEC SQL END DECLARE SECTION;
.................
EXEC SQL CONNECT :usr IDENTIFIED BY :pwd USING :conn_opt3;
....
}
The Makefile for building connect1.sc into libconn_sl.so is as follows.
Example of Makefile for shared library build#
ALTI_INCLUDE=$(ALTIBASE_HOME)/include
ALTI_LIBRARY=$(ALTIBASE_HOME)/lib
LIBS= -lc -lpthreads -lm # -lapre_sl -lodbccli_sl must be linked when building the executable file.
LFLAGS=-O2 -lc -q64 # 64bit compile mode
SHLLIB=libconn_sl.so
OBJS=connect1.o
all: $(SHLLIB)
$(SHLLIB):$(OBJS)
xlc_r -G -o $(SHLLIB) $(OBJS) -b64 -bexpall -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)
connect1.o:connect1.c
xlc_r $(LFLAGS) -c connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)
connect1.c:connect1.sc
$(ALTIBASE_HOME)/bin/apre -t c connect1.sc
clean:
rm *.o
Example of Makefile for compiling a program that calls a shared library built from APRE functions#
First, create "alticonn.h" as the header file for the APRE shared library.
/ alticonn.h /
int contest_db();
The user program is used by calling contest_db(), which is registered in libconn_sl.so.
The source of the user program is as follows.
/ test.c /
#include "alticonn.h"
extern int contest_db();
int main()
{
contest_db();
}
The Makefile for compiling the user program that calls the contest_db() function registered in libconn_sl.so is as follows.
ALTI_INCLUDE=$(ALTIBASE_HOME)/include
ALTI_LIBRARY=$(ALTIBASE_HOME)/lib
LIBS=-lapre_sl -lodbccli_sl -lc -lpthreads -lm
LFLAGS=-O2 -brtl -qinline -q64 # 64bit compile mode
INC_ALL=-I. -I$(ALTI_INCLUDE)
LIB_ALL=-L. -L$(ALTI_LIBRARY)
all:test
test:
xlc_r $(LFLAGS) -o test test.c $(INC_ALL) $(LIB_ALL) -lconn_sl $(LIBS)
clean:
rm *.c *.
Considerations when building shared library#
Note
In AIX, when creating and using more than one shared library, do not add -lapre_sl and -lodbccli_sl when building a shared library.
In the shared library of AIX, the global variables in the apre_sl and odbccli_sl libraries are each recognized as different variables, so they cannot be shared between shared libraries. Therefore, when creating a shared library, do not link the APRE libraries (apre_sl, odbccli_sl); link the APRE library only when creating the executable binary.
For example, if the connection-related shared library is con.so and the select-related shared library is sel.so, and the binaries are built and run, an error occurs because sel.so cannot reference the connection-related object information in con.so. To prevent this problem, apre_sl and odbccli_sl should be added as links only when creating the executable binary.
Makefile for HP acc#
This chapter describes the library and compile options that must be additionally described in the Makefile in an environment where HP-UX uses acc (a C compiler).
Additional library and compile options for APRE compilation in the HP-UX environment#
-
Library to be added to the Makefile
In addition to the basic APRE library "-lapre -lodbccli", refer to the table below to specify the system libraries used by APRE in the Makefile.
Library type Makefile Library Description Posix thread library -lpthread Thread library for POSIX thread functions Math-related library -lm Library for using math functions Dynamic Linking Loader (DL) Library -ldld Dynamically loaded (DL) library Unwind Express Library -lunwind Library for using APIs to perform stack tracing and stack unwinding on Itanium-based servers C++ library -lstd –lstream –lCsup -lc Specify the C++ library when compiling with the acc C compiler in Altibase 5.3.3 or earlier Realtime Extensions Library to be added -lrt -
Compile options
The following options need to be specified to improve performance and specify the compile bit type.
Option name Option Description Multithread program compile option -mt Required when writing the program as multi-thread Instruction Set Architecture (ISA) designation +DD64 Generates 64-bit code for HP-UX on IA64 +DD32 Generates 32-bit code for HP-UX on IA64 Warning option +vnocompatwarnings Option to reduce unnecessary warning messages Info
By referring to the $ALTIBASE_HOME/install/altibase_env.mk file and $ALTIBASE_HOME/sample/APRE/Makefile, you can find the optimized compile and link options for compiling APRE.
-
Example of a simple Makefile
The simplest Makefile that can compile APRE in the HP acc environment is now complete, as shown below.
In addition, if there are additional libraries referenced by the program, they must also be described in the Makefile.
ALTI_INCLUDE=$(ALTIBASE_HOME)/include ALTI_LIBRARY=$(ALTIBASE_HOME)/lib LIBS=-lapre -lodbccli -lpthread -lunwind -lm LFLAGS=-mt +DD64 -Wl,+vnocompatwarnings -L. connect1.c:connect1.sc $(ALTIBASE_HOME)/bin/apre -t c connect1.sc connect1:connect1.c cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS) clean: rm *.c *.o
Example of Makefile for 32bit compile#
An example of the APRE Makefile for acc that specifies the 32bit compile option is as follows.
Specify "+DD32" as the compile option, and specify the path where the 32bit APRE library is installed in the path referencing the header file and library.
Also specify the path so that the 32bit APRE precompiler is executed.
ALTI_INCLUDE=/alticlient32/include
ALTI_LIBRARY=/alticlient32/lib
LIBS=-lapre -lodbccli -lpthread -lunwind -lm
LFLAGS=-mt +DD32 -Wl,+vnocompatwarnings -L.
connect1.c:connect1.sc
/alticlient32/bin/apre -t c connect1.sc
connect1:connect1.c
cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)
clean:
rm *.c *.o
Makefile for SUN (Solaris) cc#
This chapter describes the library and compile options that must be additionally described in the Makefile in an environment that uses the SUN (Solaris) cc compiler.
Library and compile options for APRE compilation in the SUN (Solaris) environment#
-
Library to be added to the Makefile
In addition to the basic APRE library "-lapre -lodbccli", refer to the table below to specify the system libraries used by APRE in the Makefile.
Library type Makefile added library name Description Thread library -lpthread or -lthread Thread library for POSIX thread functions Math-related library -lm Library for using math functions Dynamic Linking Loader (DL) Library -ldl Dynamically loaded (DL) Library Networking Services Library -lnsl Library for using Networking Services functions Sockets Library -lsocket Library for using Sockets functions C++ library -lCrun -ldemangle Specify the C++ library when compiling with cc in Altibase 5.3.3 or earlier Realtime Extensions Library to be added -lrt -
Compile options
The following options need to be specified to improve performance and specify the compile bit type.
Option name Option Description Multithread program compile option -mt Required when writing the program as multi-thread Instruction Set Architecture (ISA) designation -xarch=amd64 When compiling a 64bit program on the AMD cpu (x86) platform -xarch=sse2a When compiling a 32bit program on the AMD cpu (x86) platform -xarch=v9 When compiling a 64bit program on the SUN sparc cpu platform -xarch=v8plus When compiling a 32bit program on the SUN sparc cpu platform Performance option -fast Option for improving runtime performance Info
By referring to the $ALTIBASE_HOME/install/altibase_env.mk file and $ALTIBASE_HOME/sample/APRE/Makefile, you can find the optimized compile and link options for compiling APRE.
-
Example of a simple Makefile
The simplest Makefile that can compile APRE in the SUN x86 cc environment is now complete, as shown below.
In addition, if there are additional libraries referenced by the program, they must also be described in the Makefile.
Depending on the platform type, the options for specifying the memory model (32bit/64bit) may vary, so refer to the compile option table described above and set it according to the platform type.
ALTI_INCLUDE=/altibase_home/include ALTI_LIBRARY=/altibase_home/lib LIBS=-lapre -lodbccli -lthread -lposix4 -ldl -lkvm -lkstat -lsocket -lnsl -lgen -lC -lCrun -ldemangle -lm LFLAGS=-fast -mt -xarch=amd64 -L/opt/SUNWspro/lib/amd64 -L/usr/lib/amd64 connect1.c:connect1.sc /altibase_home/bin/apre -t c connect1.sc connect1:connect1.c /opt/SUNWspro/bin/cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS) clean: rm *.c *.o
Example of Makefile for 32bit compile#
An example of the APRE Makefile for SUN x86 cc that specifies the 32bit compile option is as follows.
Specify "-xarch=sse2a" as the compile option, and specify the path where the 32bit APRE library is installed in the path referencing the header file and library.
Also specify the path so that the 32bit APRE precompiler is executed.
ALTI_INCLUDE=/alticlient32/include
ALTI_LIBRARY=/alticlient32/lib
LIBS=-lapre -lodbccli -lpthread -lrt -ldl -lkvm -lkstat -lsocket -lnsl -lgen -lm
LFLAGS=-fast -mt -xarch=sse2a -L/opt/SUNWspro/lib/amd64 -L/usr/lib/amd64
connect1.c:connect1.sc
/alticlient32/bin/apre -t c connect1.sc
connect1:connect1.c
/opt/SUNWspro/bin/cc $(LFLAGS) -o connect1 connect1.c -I$(ALTI_INCLUDE) -L$(ALTI_LIBRARY) $(LIBS)
clean:
rm *.c *.o
Notes/Considerations#
For the sake of understanding, we have looked at some errors that may occur during the make process of a simple .sc source and how to fix the errors with Makefile modification.
For compile-related problems, it is important above all to understand what type of problem it is.
When a problem related to compilation occurs, the following items are the items to be checked:
- Is the correct library being used for the compiler?
- Are there any errors in the Makefile? (Path, specification, type, variable name use, etc.)
- Are the compile bits different between libraries or objects?
- Are you correctly linking the required vendor's library?
- Are you specifying the required system library?
- Do you specify a library for compatibility between C/C++?