在上篇《FreeBSD 静态链接问题》中还有一个遗留问题,即确定一个静态库调用了其它什么库呢?google的结果令人失望,唯一的结果libtool脚本,没用过,看不懂,没google到使用方法,只好用了个笨办法。
问题源于优快云的一篇帖子http://community.youkuaiyun.com/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
这个办法很麻烦,在库很多,的情况下,工作量很大,甚至于无法完成,期待好方法出现!
4614

被折叠的 条评论
为什么被折叠?



