aix动态库(.so)编译使用

AIX 下通常用xlC来编译c++代码,例如我写了一个string的类,包含俩文件 string.h 和 string.cpp

现在我想将其编译成动态链接库(.so文件) 步骤为:

1.

$(CC) -q64 -o libstring.o -c libstring.cpp $(CFLAGS) -I$(HOME)/include -L$(LD_LIBRARY_PATH)

2.

ld -v -G -o libstring.so libstring.o common.o -b64 -bexpall -bnoentry

AIX下.so文件最好用 libxxx.so的方式来命名

3.使用动态库:

$(CC) -q64 -brtl -o libstring.o -c libstring.cpp $(CFLAGS) -I$(HOME)/include -L$(LD_LIBRARY_PATH) -lstring

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值