make 小技巧

直接編譯

當測試一下小的功能時,可以直接編譯,不需要撰寫 Makefile。

譬如經典的 hello world:

// filename: hello.c
#include <stdio.h>

int main() {
	printf("Hello, world!\n");
	return 0;
}

可以使用 make 直接編譯,make 命令後跟上 hello 即可(去掉擴展名):

$ make hello
cc     hello.c   -o hello
$ ./hello
Hello, world!
$

提供編譯選項

可以通過命令行提供編譯選項,如下面的 CFLAGS。

$ CFLAGS="-Wall -g" make hello
cc -Wall -g    hello.c   -o hello
$ ./hello
Hello, world!
$

From 《Learn C the Hard Way》Exercise 1 & 2

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章