一个开源库的静态编译

gisupc 2011-12-27 01:45:13
各位网友你们好,我最近在网上看到一个spserver开源库,想学习一下,但是这个库给的makefile文件是动态库编译的,我现在想静态编译这个库,该如何修改呢?请高手指点一下


#--------------------------------------------------------------------

CC = gcc
AR = ar cru
CFLAGS = -Wall -D_REENTRANT -D_GNU_SOURCE -g -fPIC
SOFLAGS = -shared
LDFLAGS = -lstdc++ -lpthread

LINKER = $(CC)
LINT = lint -c
RM = /bin/rm -f

LIBEVENT_INCL = -I$(HOME)/libevent/
LIBEVENT_LIB = -L$(HOME)/libevent -levent -lrt

CFLAGS += $(LIBEVENT_INCL)
LDFLAGS += $(LIBEVENT_LIB)

#--------------------------------------------------------------------

LIBOBJS = sputils.o spioutils.o spiochannel.o \
spthreadpool.o event_msgqueue.o spbuffer.o sphandler.o \
spmsgblock.o spmsgdecoder.o spresponse.o sprequest.o \
spexecutor.o spsession.o speventcb.o spserver.o \
spdispatcher.o splfserver.o \
sphttpmsg.o sphttp.o spsmtp.o

TARGET = libspserver.so libspserver.a \
testecho testthreadpool testsmtp testchat teststress testhttp \
testhttp_d testhttpmsg testdispatcher testchat_d testunp

#--------------------------------------------------------------------

all: $(TARGET)

libspserver.so: $(LIBOBJS)
$(LINKER) $(SOFLAGS) $^ -o $@

libspserver.a: $(LIBOBJS)
$(AR) $@ $^

testthreadpool: testthreadpool.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testsmtp: testsmtp.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testchat: testchat.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

teststress: teststress.o
$(LINKER) $^ -L. -levent $(LDFLAGS) -o $@

testecho: testecho.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testhttp: testhttp.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testhttp_d: testhttp_d.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testhttpmsg: sputils.o sphttpmsg.o testhttpmsg.o
$(LINKER) $^ $(LDFLAGS) -o $@

testdispatcher: testdispatcher.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testchat_d: testchat_d.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testunp: testunp.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

clean:
@( $(RM) *.o vgcore.* core core.* $(TARGET) )

#--------------------------------------------------------------------

# make rule
%.o : %.c
$(CC) $(CFLAGS) -c $^ -o $@

%.o : %.cpp
$(CC) $(CFLAGS) -c $^ -o $@



请高人给指点一下谢谢
...全文
149 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
gisupc 2011-12-27
  • 打赏
  • 举报
回复
以下是我修改的静态库,编译没问题,但是使用的时候总是提示很多函数未定义


#--------------------------------------------------------------------

CC = gcc
AR = ar cru
CFLAGS = -Wall -D_REENTRANT -D_GNU_SOURCE -g
LDFLAGS = -lstdc++ -lpthread

LINKER = $(CC)
LINT = lint -c
RM = /bin/rm -f

LIBEVENT_INCL = -I$(HOME)/libevent/
LIBEVENT_LIB = -L$(HOME)/libevent -levent -lrt

CFLAGS += $(LIBEVENT_INCL)
LDFLAGS += $(LIBEVENT_LIB)

#--------------------------------------------------------------------

LIBOBJS = sputils.o spioutils.o spiochannel.o \
spthreadpool.o event_msgqueue.o spbuffer.o sphandler.o \
spmsgblock.o spmsgdecoder.o spresponse.o sprequest.o \
spexecutor.o spsession.o speventcb.o spserver.o \
spdispatcher.o splfserver.o \
sphttpmsg.o sphttp.o spsmtp.o

TARGET = libspserver.a \
testecho testthreadpool testsmtp testchat teststress testhttp \
testhttp_d testhttpmsg testdispatcher testchat_d testunp

#--------------------------------------------------------------------

all: $(TARGET)

libspserver.a: $(LIBOBJS)
$(AR) $@ $^

testthreadpool: testthreadpool.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testsmtp: testsmtp.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testchat: testchat.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

teststress: teststress.o
$(LINKER) $^ -L. -levent $(LDFLAGS) -o $@

testecho: testecho.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testhttp: testhttp.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testhttp_d: testhttp_d.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testhttpmsg: sputils.o sphttpmsg.o testhttpmsg.o
$(LINKER) $^ $(LDFLAGS) -o $@

testdispatcher: testdispatcher.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testchat_d: testchat_d.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

testunp: testunp.o
$(LINKER) $^ -L. -lspserver $(LDFLAGS) -o $@

clean:
@( $(RM) *.o vgcore.* core core.* $(TARGET) )

#--------------------------------------------------------------------

# make rule
%.o : %.c
$(CC) $(CFLAGS) -c $^ -o $@

%.o : %.cpp
$(CC) $(CFLAGS) -c $^ -o $@


374

社区成员

发帖
与我相关
我的任务
社区描述
CUDA on Linux
社区管理员
  • CUDA on Linux社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧