关于AIX 5L平台下gcc for AIX编译Oracle Pro*C/C++程序值得注意的几个问题
#################################################################################
Note1: AIX 5L下Oracle 9i/10g编译Pro*C/C++、OCI程序的时候有时候会找不到
$ORACLE_HOME/lib/libclntsh.so共享库的问题:
Question:
Why do I get error "[unixODBC][Easysoft][Oracle]Could not open
libclntsh.a
No such file or directory [ISQL]ERROR: Could not SQLConnect" on
AIX? Article : 00741
Last Reviewed : 14th February 2006
Revision : 1
Answer:
The libclntsh.a is an "archived" file which cannot be opened by
our driver. The way around
this is to "unarchive" this file and extract the shared object.
This can be done by changing
directory to $ORACLE_HOME/lib ($ORACLE_HOME/lib32 if you are not
using the 64-bit library)
and typing ar -xv libclntsh.a.
This will then generate a file called shr.o which will then need
to be renamed to libclntsh.so.
From this, the driver will be able to load the required shared
object.
Please then make sure that $ORACLE_HOME/lib (/lib32) is added to
your LIBPATH.
AIX 5L
$ cd $ORACLE_HOME/lib
$ ar -X32_64 -xv libclntsh.a
x - shr.o
$ mv shr.o libclntsh.so
$ cd $ORACLE_HOME/lib32
$ ar -xv libclntsh.a
x - shr.o
$ mv shr.o libclntsh.so
########################################################################################
Note2 :
AIX 5L下gcc编译Oracle Pro*C程序时,gcc for AIX
5L要加上-maix32或者-maix64的开关选项
CFLAGS = -maix32 #编译成32bit的目标文件
CFLAGS = -maix64 #编译成64bit的目标文件
########################################################################################
Note3 :
关于gcc的链接器如何使用静态库来解析引用,书上说命令行上的库和目标文件的顺序非常重要,如果在命令行中,
定义一个符号的库出现在引用这个符号的目标文件之前,那么引用就不能被解析,链接会失败。我查了一下gcc的
manual,也是这么说的:
(liboratest.a是包含了Pro*C/C++例程sqlcxt(),sqlglm()函数调用的静态库)
gcc -o -g -maix64 -L$ORACLE_HOME/lib -lclntsh -o test test.o
../../src/db/liboratest.a
出错: 报告:
.Undefined Symbol: '.sqlcxt'等等
改写为:
gcc -o -g -maix64 -o test test.o
../../src/db/liboratest.a -L$ORACLE_HOME/lib
-lclntsh
则链接OK
根据上面的描述,则:
如果需要编译链接的可执行文件同时使用liboratest.a静态库和链接$ORACLE_HOME/lib/libclntsh.so动态库,
则Makefile.am中宏定义如下:
e.g.:
bin_PROGRAM=test
test_LDADD=$(top_srcdir)/src/lib/libdes.a
$(top_srcdir)/src/db/liboratest.a
test_LDADD+=-L$(ORACLE_HOME)/lib -lclntsh
########################################################################################