unix – 如何使makefile中的静态库
发布时间:2020-12-15 18:21:18 所属栏目:安全 来源:网络整理
导读:我现在有以下makefile到目前为止 # Beginning of MakefileOBJS = obj/shutil.o obj/parser.o obj/sshell.oHEADER_FILES = include/shell.h include/parser.hSTATLIB = lib/libparser.a lib/libshell.aEXECUTABLE = sshellCFLAGS = -WallCC = gcc# End of con
|
我现在有以下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 $@ $<
#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 我不知道如何创建这些静态库… 解决方法
您使用ar命令创建静态库:
lib/libparser.a: $(OBJECT_FILES_FOR_LIBPARSER)
ar rcs $@ $^
lib/libshell.a: $(OBJECT_FILES_FOR_LIBSHELL)
ar rcs $@ $^
如果您的ar命令不明白s选项,则必须在ar生成的.a文件上运行ranlib.在这种情况下,将ar rc $@ $^替换为ar rc $@ $^&&& ranlib $@. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
