我有3个程序 abc.c pqr.c 和 xyz.c 我这样编译:
/usr/bin/gcc -pthread -O2 -fmessage-length=0 -pedantic-errors -std=gnu99 -Werror -Wall -Wextra -Wwrite-strings -Winit-self -Wcast-align -Wcast-qual -Wpointer-arith -Wstrict-aliasing -Wformat=2 -Wmissing-include-dirs -Wno-unused-parameter -Wshadow -Wuninitialized -Wold-style-definition filename.c -o filename
我想编写一个makefile来使用上面的选项编译这三个程序并生成三个可执行文件。我已经阅读了一些教程并阅读了手册页,所以请不要问我Google。 如果你能给我直接答案,那就太棒了。谢谢! :)
答案 0 :(得分:-1)
我是自己编码的新手,我不知道这是否有效。但是当我必须编译多个c文件时,我使用了这个命令:
gcc -c abc.c
gcc -c pqr.c
gcc -c xyz.c
然后链接: gcc -o abcxyz abc.o pqr.o xyz.o
答案 1 :(得分:-1)
我认为这样做会:
CC := /usr/bin/gcc
CFLAGS += -pthread -O2 -fmessage-length=0 -pedantic-errors # and so on
.PHONY: all
all: abc pqr xyz