FreeBSD 静态链接问题 (2) libpqxx & libpq

在上篇《FreeBSD 静态链接问题》中还有一个遗留问题,即确定一个静态库调用了其它什么库呢?google的结果令人失望,唯一的结果libtool脚本,没用过,看不懂,没google到使用方法,只好用了个笨办法。

问题源于CSDN的一篇帖子http://community.csdn.net/Expert/TopicView.asp?id=5630522
简单的说,就是需要静态链接libpqxx和libpq,帖子主人发现问题所在:使用libtool生成的库,通常会带一个.la的文件说明文件,说明库的名称、要求的库、版本和安装路径,libpqxx.la内容如下:

#  libpqxx.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.5.22 Debian 1.5.22-4 (1.1220.2.365 2005/12/18 22:14:06)
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).

dlname = ' libpqxx-2.6.9.so '

#  Names of this library.
library_names = ' libpqxx-2.6.9.so libpqxx-2.6.9.so libpqxx.so '

#  The name of the static archive.
old_library = ' libpqxx.a '

#  Libraries that this one depends upon.
dependency_libs = '  -L/usr/local/lib -lpq '

#  Version information for libpqxx.
current = 0
age
= 0
revision
= 0

#  Is this an already installed library?
installed = yes

#  Should we warn about portability when linking against -modules?
shouldnotlink = no

#  Files to dlopen/dlpreopen
dlopen = ''
dlpreopen
= ''

#  Directory that this library needs to be installed in:
libdir = ' /usr/local/lib '

libpqxx要求libpq,可是找不到一个libpq.la的文件,静态链接总是失败。用objdump -t libpq.so检查的libpq.so符号显示no symbols,strip过的,查看libpq.a会逐显示libpq.a里的.o文件的符号,不容易确定那些是真正的外部符号,实在没有办法了,只好解开libpq.a,然后重新链接成.so文件,就可以用objdump -t 看看有哪些外部符号了,终于确定了libpq 调用的函数库,libpqxx终于可以静态链接到应用程序了。下面是编译libpqxx中的测试程序的一个Makefile

#
#
 Makefile - static linked to libpqxx
#

CFLAGS  
+=   - static  - I / usr / local / include
LDFLAGS 
+=   - L / usr / local / lib
LDLIBS  
+=   - lpqxx  - lstdc ++   - lpq  - lcrypt  - lssl  - lcrypto  - lintl  - liconv

PROG     
=  test094
OBJS     
=  test094.o

RM       
=  rm  - rf

all: $(PROG)

test094: $(OBJS)
    $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) 
- o $@

clean:
    $(RM) $(PROG) $(OBJS)

系统信息:
FreeBSD 5.4-RELEASE
gcc version 3.4.2 [FreeBSD] 20040728
postgresql-client-7.4.17
postgresql-libpqxx-2.6.9

这个办法很麻烦,在库很多,的情况下,工作量很大,甚至于无法完成,期待好方法出现!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值