您的位置:程序门 -> linux/unix社区 -> 程序开发区



动态连接库和静态连接库的问题 在线等待.......!!!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


动态连接库和静态连接库的问题 在线等待.......!!![已结贴,结贴人:linqzly]
发表于:2007-09-05 13:55:30 楼主
比如有这些个文件   a.c   b.c   d.c
然后这些文件做成一个静态连接库m.a
如下:
src   =   a.c   b.c   d.c
obj   =   $(src:%.c=%.o)
lib   =   m.a

all: $(src)   $(obj)
$(ar)   ro   $(lib)   $(obj)
$(obj):   %.o:   %.c
$(cc)   -c   $(cflags)   $ <   -o   $@  
但是现在有个问题是:d.c需要使用到一个动态连接库中(如-lssl)的函数,所以应该将动态连接库也连接进来.
那么请问上面的编译命令应该怎么修改,才能达到我想要的效果呢?
发表于:2007-09-05 13:58:281楼 得分:0
我还是不喜欢这种makefile,   还是分开写比较好.
发表于:2007-09-05 15:07:142楼 得分:5
但是现在有个问题是:d.c需要使用到一个动态连接库中(如-lssl)的函数,所以应该将动态连接库也连接进来.  
那么请问上面的编译命令应该怎么修改,才能达到我想要的效果呢?
====
这个问题应该在链接阶段去解决!原因分析如下:
1.   楼主提供的产品是程序库,只需要告诉客户m.a需要用libssl就可以了;
2.   动态链接或静态链接应该让客户去选择;
3.   更好的选择是同时提供库的动态和静态版本;
还有几个个建议:
1.   m.a的命名不是很规范,通常应该以lib开头,比如libc,   libxml2,   libz
2.   建议使用gnu的libtool,可以很好的进行版本维护
发表于:2007-09-05 15:29:593楼 得分:0
谢谢楼上的建议,但是现在是具体到这个问题应该怎么解决呢,执行下面的语句
all:   $(src)   $(obj)  
        $(ar)   ro   $(lib)   $(obj)
会报错,d.c没有引用相关的函数。那怎么样把动态连接库的函数也加入到静态连接库当中呢?有没有这样的方法呢?
谢谢!
 
发表于:2007-09-05 15:48:224楼 得分:10
all:   $(src)   $(obj)    
        $(ar)   ro   $(lib)   $(obj)  

这个只是链接阶段,不需要用到库,所以报错不是因为没有-lssl的原因,建议把报错原因贴出来。
发表于:2007-09-05 16:01:125楼 得分:0
[root@localhost   hydra]#   make
make   --no-print-directory   -c   event
./event/libevent.a(httppost_notify.o)(.text+0x10):   in   function   `check_cert':
httppost_notify.c:   undefined   reference   to   `ssl_get_peer_certificate'
./event/libevent.a(httppost_notify.o)(.text+0x28):httppost_notify.c:   undefined   reference   to   `ssl_get_verify_result'
./event/libevent.a(httppost_notify.o)(.text+0x40):httppost_notify.c:   undefined   reference   to   `x509_get_subject_name'
./event/libevent.a(httppost_notify.o)(.text+0x60):httppost_notify.c:   undefined   reference   to   `x509_name_get_text_by_nid'
./event/libevent.a(httppost_notify.o)(.text+0xf0):   in   function   `initialize_ctx':
httppost_notify.c:   undefined   reference   to   `ssl_library_init'
./event/libevent.a(httppost_notify.o)(.text+0xf4):httppost_notify.c:   undefined   reference   to   `sslv23_client_method'
./event/libevent.a(httppost_notify.o)(.text+0xf8):httppost_notify.c:   undefined   reference   to   `ssl_ctx_new'
./event/libevent.a(httppost_notify.o)(.text+0x110):httppost_notify.c:   undefined   reference   to   `ssl_ctx_use_certificate_chain_file'
./event/libevent.a(httppost_notify.o)(.text+0x134):httppost_notify.c:   undefined   reference   to   `ssl_ctx_set_default_passwd_cb'
./event/libevent.a(httppost_notify.o)(.text+0x144):httppost_notify.c:   undefined   reference   to   `ssl_ctx_use_privatekey_file'
./event/libevent.a(httppost_notify.o)(.text+0x164):httppost_notify.c:   undefined   reference   to   `ssl_ctx_load_verify_locations'
./event/libevent.a(httppost_notify.o)(.text+0x184):httppost_notify.c:   undefined   reference   to   `ssl_ctx_free'
./event/libevent.a(httppost_notify.o)(.text+0x63c):   in   function   `httppost_send_request':
httppost_notify.c:   undefined   reference   to   `ssl_write'
./event/libevent.a(httppost_notify.o)(.text+0x694):httppost_notify.c:   undefined   reference   to   `ssl_write'
./event/libevent.a(httppost_notify.o)(.text+0x718):httppost_notify.c:   undefined   reference   to   `ssl_shutdown'
./event/libevent.a(httppost_notify.o)(.text+0x728):httppost_notify.c:   undefined   reference   to   `ssl_free'
./event/libevent.a(httppost_notify.o)(.text+0x730):httppost_notify.c:   undefined   reference   to   `ssl_ctx_free'
./event/libevent.a(httppost_notify.o)(.text+0x748):httppost_notify.c:   undefined   reference   to   `ssl_shutdown'
./event/libevent.a(httppost_notify.o)(.text+0x7c0):httppost_notify.c:   undefined   reference   to   `ssl_read'
./event/libevent.a(httppost_notify.o)(.text+0x944):httppost_notify.c:   undefined   reference   to   `ssl_new'
./event/libevent.a(httppost_notify.o)(.text+0x95c):httppost_notify.c:   undefined   reference   to   `bio_new_socket'
./event/libevent.a(httppost_notify.o)(.text+0x96c):httppost_notify.c:   undefined   reference   to   `ssl_set_bio'
./event/libevent.a(httppost_notify.o)(.text+0x974):httppost_notify.c:   undefined   reference   to   `ssl_connect'
./event/libevent.a(httppost_notify.o)(.text+0x9a4):httppost_notify.c:   undefined   reference   to   `ssl_ctx_free'
collect2:   ld   returned   1   exit   status
make:   ***   [hydra]   error   1
发表于:2007-09-05 17:34:586楼 得分:0
修改./event/makefile,在-levent这类的地方,加上-lssl
发表于:2007-09-05 18:42:577楼 得分:0
楼上正解!
发表于:2007-09-05 18:45:398楼 得分:0
all:   $(src)   $(obj)      
        $(ar)   ro   $(lib)   $(obj)    

这个只是链接阶段,不需要用到库,所以报错不是因为没有-lssl的原因,建议把报错原因贴出来。
==============================================================================
这个只是链接阶段?   是不是说错了,   你想说编译阶段吧.
发表于:2007-09-05 22:41:599楼 得分:5
哦哦~~~~~打错了~~
发表于:2007-09-06 15:02:4510楼 得分:0
谢谢各位了,原来是我将-lssl放错了地方。


快速检索

最新资讯
热门点击