c文件在不同目录的情况makefile怎么写

2025-03-12 22:43:38
推荐回答(1个)
回答1:

c文件在不同目录的情况makefile怎么写
假设有下面几个c++文件:
wherewhen.h wherewhen.c
countdown.h countdown.c 包含了math.h, 需要连接库文件
main.c 主函数, main.c 包含了两个头文件 wherewhen.h and countdown.h
1、第一种编译方法:
g++ -Wall -g wherewhen.c countdown.c main.c -lm -o myprogram
生成可执行文件myprogram
2、第二中编译方法, 分别编译各个文件:
g++ -Wall -g -c wherewhen.c
g++ -Wall -g -c countdown.c
g++ -Wall -g -c main.c
g++ -g wherewhen.o countdown.o main.o -lm -o myprogram