原始命令
gcc -lstdc++ -Wall -lpthread -g -o test test.c && ./test
假若存在test.c,可以使用以下几种方式编写,再执行make命令即可
方式1
test:test.o
gcc -std=c99 -Wall -lpthread -g -o test test.o
test.o:test.c
gcc -c test.c
方式2
test:test.o
gcc -std=c99 -Wall -lpthread -g -o $@ $^
test.o:test.c
gcc -c $<
- $@表示当前目标文件
- $^表示所有依赖文件
- $<表示第一个依赖文件
- $?表示比当前目标更新的已修改的依赖性文件
方式3
test:test.o
gcc -std=c99 -Wall -lpthread -g -o $@ $^
.c.o:
gcc -c $<
- .c.o:为Makefile的缺省规则,表示所有o文件都是由c结尾文件编译生成的