diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6cd008a..0126bb1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -19,5 +19,5 @@ } }, "initializeCommand": "gdb -ex 'set confirm off' -ex quit", // 初始化GDB配置 - "postAttachCommand": "make debug" // 假设你的Makefile有debug目标 + "postAttachCommand": "make debug" } \ No newline at end of file diff --git a/Makefile b/Makefile index b22fcf0..2b0643a 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include ./make.h # 目标和源文件 -TARGETS = fork execlp +TARGETS = fork execlp getSum SOURCES = $(wildcard $(SRC_DIR)/*.c) # 找到所有的 .c 文件 OBJECTS = $(patsubst $(SRC_DIR)/%.c,%.o,$(SOURCES)) # 将 .c 替换为 .o @@ -26,6 +26,9 @@ fork: fork.o execlp: execlp.o $(CC) -o execlp execlp.o +getSum: getSum.o + $(CC) -o getSum getSum.o + # 从 .c 文件编译生成 .o 文件 %.o: $(SRC_DIR)/%.c $(CC) $(CFLAGS) $(COMMON_INCLUDE_DIRS) -c $< -o $@ diff --git a/getSum b/getSum new file mode 100755 index 0000000..085e52f Binary files /dev/null and b/getSum differ diff --git a/src/getSum.c b/src/getSum.c new file mode 100644 index 0000000..41a00f5 --- /dev/null +++ b/src/getSum.c @@ -0,0 +1,16 @@ +#include + +int getSum(void) +{ + int sum = 0; + for (int i = 1; i <= 100; ++i) { + sum += i; + } + return sum; +} + +int main(void) +{ + printf("%d\n", getSum()); + return 0; +} \ No newline at end of file