gpt4 book ai didi

unix - 如何在makefile中制作静态库

转载 作者:行者123 更新时间:2023-12-04 02:13:00 29 4
gpt4 key购买 nike

到目前为止,我有以下生成文件...

# 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选项,你必须运行 ranlib.a文件由 ar 生成以及。在这种情况下,请替换 ar rcs $@ $^ar rc $@ $^ && ranlib $@ .

关于unix - 如何在makefile中制作静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15195087/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com