2013-03-04 71 views
11

我有以下生成文件迄今現在...如何使靜態庫makefile中

# Beginning of Makefile 

OBJS = obj/shutil.o obj/parser.o obj/sshell.o 
HEADER_FILES = include/shell.h include/parser.h 
STATLIB = lib/libparser.a lib/libshell.a 
EXECUTABLE = sshell 
CFLAGS = -Wall 
CC = gcc 
# End of configuration options 

#What needs to be built to make all files and dependencies 
all: $(EXECUTABLE) $(STATLIB) 

#Create the main executable 
$(EXECUTABLE): $(OBJS) 
     $(CC) -o $(EXECUTABLE) $(OBJS) 

$(STATLIB): $(
#Recursively build object files 
obj/%.o: src/%.c 
     $(CC) $(CFLAGS) -I./include -c -o [email protected] $< 


#Define dependencies for objects based on header files 
#We are overly conservative here, parser.o should depend on parser.h only 
$(OBJS) : $(HEADER_FILES) 

clean: 
     -rm -f $(EXECUTABLE) obj/*.o 
     -rm -f lib/*.a 

run: $(EXECUTABLE) 
     ./$(EXECUTABLE) 

tarball: 
     -rm -f $(EXECUTABLE) *.o 
     (cd .. ; tar czf Your_Name_a1.tar.z shell) 

# End of Makefile 

我試圖產生libparser.a和libshel​​l.a

靜態庫我沒有知道如何創建這些靜態庫...

+0

http://www.adp-gmbh.ch/cpp/gcc/create_lib.html – 2013-03-04 05:26:19

回答

9

創建與ar命令靜態庫:

lib/libparser.a: $(OBJECT_FILES_FOR_LIBPARSER) 
     ar rcs [email protected] $^ 

lib/libshell.a: $(OBJECT_FILES_FOR_LIBSHELL) 
     ar rcs [email protected] $^ 

如果您的ar命令不理解s選項,則您還必須在由ar生成的.a文件上運行ranlib。在這種情況下,請將ar rcs [email protected] $^替換爲ar rc [email protected] $^ && ranlib [email protected]

+0

它不是''rcs'而不是'rcs'嗎? – deddebme 2017-04-06 15:30:25