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 文件来进行处理。

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值