当前位置: 技术问答>linux和unix
怎样将整个工程编译成静态库?
来源: 互联网 发布时间:2014-12-15
本文导语: 也就是说有很多c和h文件 | such as: C_OBJ=a.o b.o c.a : a.h b.h $(C_OBJ) ar rv $@ $(C_OBJ) Just try and modify it yourself I have no way to prove it's correctivity | 给你一个例子...
也就是说有很多c和h文件
|
such as:
C_OBJ=a.o b.o
c.a : a.h b.h $(C_OBJ)
ar rv $@ $(C_OBJ)
Just try and modify it yourself
I have no way to prove it's correctivity
C_OBJ=a.o b.o
c.a : a.h b.h $(C_OBJ)
ar rv $@ $(C_OBJ)
Just try and modify it yourself
I have no way to prove it's correctivity
|
给你一个例子吧
# Generated automatically from Makefile.in by configure.
##
## Makefile for libsnmp.
##
## because this is for Linux with ELF only, we are building
## a shared lib, to be installed in /lib.
##
## set to installation prefix (overridden by configure --prefix=path):
prefix=/usr
VERSION = 3.7
OSHLIB= libsnmp.so
ALIB = libsnmp.a
TARG= libsnmp.so
CSRCS= snmp_client.c snmp.c snmp_auth.c asn1.c mib.c parse.c snmp_api.c
md5.c usec.c snmpdump.c
OBJS= snmp_client.o snmp.o snmp_auth.o asn1.o mib.o parse.o snmp_api.o
md5.o usec.o snmpdump.o
CC= cc
FLAGS= -g -O
DEFS=
MIBDEFS= -DMIBFILEPATH="$(prefix)/lib"
# CFLAGS=-O -DDEBUG -DBSD4_3
CFLAGS= -fPIC $(FLAGS) $(DEFS) $(CONFDEFS)
all: $(TARG)
$(OSHLIB): ${OBJS}
$(CC) -shared -Wl,-soname,$(OSHLIB).$(VERSION) -o $(OSHLIB).$(VERSION) $(OBJS)
ln -sf $(OSHLIB).$(VERSION) $(OSHLIB)
$(ALIB): ${OBJS}
ar r $(ALIB) ${OBJS}
ranlib $(ALIB)
##
## special rule to include -DMIBFILEPATH=...:
##
mib.o: mib.c
$(CC) $(CFLAGS) $(MIBDEFS) -c mib.c
clean:
rm -f core *.o ${TARG} shared/*.o *.a *.so*
# install: ../lib/libsnmp.a
#
# ../lib/libsnmp.a: libsnmp.a
# cp libsnmp.a ../lib
# ranlib ../lib/libsnmp.a
#
# lint:
# lint -nhx $(CSRCS)
asn1.o: ./asn1.h
mib.o: ./asn1.h
mib.o: ./snmp_impl.h
mib.o: ./snmp_api.h
mib.o: ./parse.h
parse.o: ./parse.h
snmp.o: ./asn1.h
snmp.o: ./snmp.h
snmp.o: ./snmp_impl.h
snmp.o: ./mib.h
snmp_api.o: ./asn1.h
snmp_api.o: ./snmp.h
snmp_api.o: ./snmp_impl.h
snmp_api.o: ./snmp_api.h
snmp_auth.o: ./asn1.h
snmp_auth.o: ./snmp.h
snmp_auth.o: ./snmp_impl.h
snmp_client.o: ./asn1.h
snmp_client.o: ./snmp.h
snmp_client.o: ./snmp_impl.h
snmp_client.o: ./snmp_api.h
snmp_client.o: ./snmp_client.h
这是snmplib库的生成makefile
# Generated automatically from Makefile.in by configure.
##
## Makefile for libsnmp.
##
## because this is for Linux with ELF only, we are building
## a shared lib, to be installed in /lib.
##
## set to installation prefix (overridden by configure --prefix=path):
prefix=/usr
VERSION = 3.7
OSHLIB= libsnmp.so
ALIB = libsnmp.a
TARG= libsnmp.so
CSRCS= snmp_client.c snmp.c snmp_auth.c asn1.c mib.c parse.c snmp_api.c
md5.c usec.c snmpdump.c
OBJS= snmp_client.o snmp.o snmp_auth.o asn1.o mib.o parse.o snmp_api.o
md5.o usec.o snmpdump.o
CC= cc
FLAGS= -g -O
DEFS=
MIBDEFS= -DMIBFILEPATH="$(prefix)/lib"
# CFLAGS=-O -DDEBUG -DBSD4_3
CFLAGS= -fPIC $(FLAGS) $(DEFS) $(CONFDEFS)
all: $(TARG)
$(OSHLIB): ${OBJS}
$(CC) -shared -Wl,-soname,$(OSHLIB).$(VERSION) -o $(OSHLIB).$(VERSION) $(OBJS)
ln -sf $(OSHLIB).$(VERSION) $(OSHLIB)
$(ALIB): ${OBJS}
ar r $(ALIB) ${OBJS}
ranlib $(ALIB)
##
## special rule to include -DMIBFILEPATH=...:
##
mib.o: mib.c
$(CC) $(CFLAGS) $(MIBDEFS) -c mib.c
clean:
rm -f core *.o ${TARG} shared/*.o *.a *.so*
# install: ../lib/libsnmp.a
#
# ../lib/libsnmp.a: libsnmp.a
# cp libsnmp.a ../lib
# ranlib ../lib/libsnmp.a
#
# lint:
# lint -nhx $(CSRCS)
asn1.o: ./asn1.h
mib.o: ./asn1.h
mib.o: ./snmp_impl.h
mib.o: ./snmp_api.h
mib.o: ./parse.h
parse.o: ./parse.h
snmp.o: ./asn1.h
snmp.o: ./snmp.h
snmp.o: ./snmp_impl.h
snmp.o: ./mib.h
snmp_api.o: ./asn1.h
snmp_api.o: ./snmp.h
snmp_api.o: ./snmp_impl.h
snmp_api.o: ./snmp_api.h
snmp_auth.o: ./asn1.h
snmp_auth.o: ./snmp.h
snmp_auth.o: ./snmp_impl.h
snmp_client.o: ./asn1.h
snmp_client.o: ./snmp.h
snmp_client.o: ./snmp_impl.h
snmp_client.o: ./snmp_api.h
snmp_client.o: ./snmp_client.h
这是snmplib库的生成makefile
|
你们不用Makefile吗?
如:
lib:
lib(file1.o) lib(file2.o)
.xx.a:
$(CC) -c $(CFLAGS) $
如:
lib:
lib(file1.o) lib(file2.o)
.xx.a:
$(CC) -c $(CFLAGS) $