[英]Sample makefile for gcc
Is there any sample makefile project that only consists of .c and .h files? 是否有仅由.c和.h文件组成的示例makefile项目?
I am using gcc, Windows 8.1 我正在使用Windows 8.1的gcc
I found this, but it does not work: 我发现了这一点,但它不起作用:
#########################
# customise these
CFILES := sampleA.c main.c sampleB.
PROG := prog
CFLAGS := -Wall -Wextra -g
LDFLAGS :=
########################
# -MMD generates dependencies while compiling
CFLAGS += -MMD
CC := gcc
OBJFILES := $(CFILES:.c=.o)
DEPFILES := $(CFILES:.c=.d)
$(PROG) : $(OBJFILES)
$(LINK.o) $(LDFLAGS) -o $@ $^
clean :
rm -f $(PROG) $(OBJFILES) $(DEPFILES)
-include $(DEPFILES)
I get the following error: 我收到以下错误:
undefined reference to sendto@24,socket@12,inte_addre@4, htons@04,bind@12, select@20,recvfrom@24, WSAGetLastError@0,WSAStartup@8,ioctlsocket@12
You can refer the below Makefile 您可以参考下面的Makefile
exe ?= prog
CC = gcc
CFLAGS = -g -Wall -Wextra -MMD
LDFLAGS =
all: $(exe)
$(exe) : sampleA.c sampleB.c main.c
$(CC) $(CFLAGS) $^ -o $@
clean:
-rm $(exe)
Here prog
is output executable at the end of make. 这里
prog
在make的末尾输出可执行文件。
You are missing some required library, wsock32
and ws2_32
if I'm not mistaken. 如果我没记错的话,您会缺少一些必需的库
wsock32
和ws2_32
。
Use this Makefile: 使用此Makefile:
EXE := prog.exe
SRC := $(wildcard *.c)
OBJ := $(SRC:.c=.o)
DEP := $(OBJ:.o=.d)
CC := gcc
CPPFLAGS := -MMD -MP
CFLAGS := -W -Wall -g
LDFLAGS :=
LDLIBS := -lwsock32 -lws2_32
.PHONY: all clean fclean re
all: $(EXE)
$(EXE): $(OBJ)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
clean:
$(RM) $(OBJ) $(DEP)
fclean: clean
$(RM) $(EXE)
re: fclean all
-include $(DEP)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.