2013-03-04 6 views
11

statische Bibliothek machen ich habe folgendes Makefile so weit jetzt ...Wie in Make-Datei

# 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 

Ich versuche, statische Bibliotheken libparser.a und libshell.a

ich nicht haben zu generieren Vorstellung davon, wie diese statischen Bibliotheken erstellen ...

+0

http://www.adp-gmbh.ch/cpp/gcc/create_lib.html –

Antwort

9

Sie erstellen statische Bibliotheken mit dem ar Befehl:

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

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

Wenn Ihr ar Befehl die s Option nicht versteht, müssen Sie ranlib auf der .a Datei ausführen, die von ar ebenfalls erzeugt wird. Ersetzen Sie in diesem Fall ar rcs [email protected] $^ durch ar rc [email protected] $^ && ranlib [email protected].

+0

es nicht annehmen 'statt nur' rcs' werden -rcs'? – deddebme

Verwandte Themen