用 1 main 编译多个 C 和头文件
Compiling multiple C and header files with 1 main
[我目录中的文件][1]
需要编译 make 文件的帮助。
所以我有这个 link 我正在做的清单作业和指示。
stringlist.h 应该包含节点和函数原型
stringlist.c 应该完成 stringlist.h 中定义的功能。但是 stringlist.c 根本不应该包含 main 。然后,namelist.c 应该包含 main 并且只有 I/O 并且它应该调用 stringlist.c.
中的命令函数
所以要编译这个我们应该创建一个 make 文件。每当我尝试时,我都会收到错误消息,因为 main 不会在其中一个 c 文件中退出。在整个学期中,我们编译了这样的代码 "gcc -std=gnu99 -m32 -Wall -g -o file file.c"
但是没用。
我将如何创建 make 文件?花了好几个小时还是想不通。
试试这个:
OBJ := namelist.c stringlist.c
GCC := gcc -g
CFLAGS := -std=gnu99 -m32 -Wall
compile: $(OBJ)
$(GCC) $(CFLAGS) $(OBJ) -o executable
正如 Jonathan Leffler 所说,我提供的示例 Makefile 有一些不好的想法。这里有一个改进:
# compiler:
CC = gcc
# compiler flags:
CFLAGS = -g -Wall
# the build target executable:
TARGET = executable
# object files to build:
OBJ = namelist.o stringlist.o
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJ)
[我目录中的文件][1]
需要编译 make 文件的帮助。
所以我有这个 link 我正在做的清单作业和指示。 stringlist.h 应该包含节点和函数原型 stringlist.c 应该完成 stringlist.h 中定义的功能。但是 stringlist.c 根本不应该包含 main 。然后,namelist.c 应该包含 main 并且只有 I/O 并且它应该调用 stringlist.c.
中的命令函数所以要编译这个我们应该创建一个 make 文件。每当我尝试时,我都会收到错误消息,因为 main 不会在其中一个 c 文件中退出。在整个学期中,我们编译了这样的代码 "gcc -std=gnu99 -m32 -Wall -g -o file file.c" 但是没用。
我将如何创建 make 文件?花了好几个小时还是想不通。
试试这个:
OBJ := namelist.c stringlist.c
GCC := gcc -g
CFLAGS := -std=gnu99 -m32 -Wall
compile: $(OBJ)
$(GCC) $(CFLAGS) $(OBJ) -o executable
正如 Jonathan Leffler 所说,我提供的示例 Makefile 有一些不好的想法。这里有一个改进:
# compiler:
CC = gcc
# compiler flags:
CFLAGS = -g -Wall
# the build target executable:
TARGET = executable
# object files to build:
OBJ = namelist.o stringlist.o
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJ)