首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

AIX上用xlcl编译以及使用.so的方法

2012-08-02 
AIX下用xlcl编译以及使用.so的方法AIX下用xlcl编译以及使用.so的方法AIX 下通常用xlC来编译c++代码,例如我

AIX下用xlcl编译以及使用.so的方法

AIX下用xlcl编译以及使用.so的方法


AIX 下通常用xlC来编译c++代码,例如我写了一个string的类,包含俩文件 string.h 和 string.cpp ,现在我想将其编译成动态链接库(.so文件),方法为:

xlC -G -o libstring.so string.cpp

AIX下.so文件最好用 libxxxxx.so的方式来命名,因为在后面与其他文件一起编译链接成可执行文件时会好办些

我又写了一个test.cpp 包含main方法 用来测试string.so中的类是不是可以正常使用,现在我们假设libstring.so文件的path为:/home/hello/lib 那么编译链接成可执行文件时,命令为:

xlC -brtl -L/home/hello/lib -lstring -o test test.cpp
(如果找不到,用xlC -brtl /home/hello/lib/libstring.so -o test test.cpp)
xlC中: -brtl表示: Enables run-time linking for the output file.? DCE thread libraries and heap debug libraries are not compatible with run-time linking. Do not specify the -brtl compiler option if you are invoking the compiler with xlc_r4 or xlC_r4, or if the -qheapdebug compiler option is specified.
??? 就是对于输出的可执行文件,启动运行时动态链接,根据公司头的解释,在加入这项时,连接器会在可执行文件和.so文件之间建立一个签名(signature),用来说明他们俩的接口,而.so文件的搜寻和载入则是由OS来负责的。

? -L说明.so文件或者.a文件(静态链接库)所在的path,-l说明链接库的名称,比如 我们写 -lxxx ,连接器会去搜寻 libxxx.so 或者 libxxx.a 文件来进行处理。

?

?

注:

xlc对应-g;

xlC对应-g或-G。

否则编译后,运行时报如下错误:

exec(): 0509-036 Cannot load program ./t because of the following errors:
??????? 0509-151 The program does not have an entry point or
?????????????????? the o_snentry field in the auxiliary header is invalid.
??????? 0509-194 Examine file headers with the 'dump -ohv' command.

热点排行