Linux程序员必须学会GNU make来管理自己的软件工程。GNU 的make只需要执行一个命令即可让整个软件项目编译链接完成。具体的一些Makefile的参考资料详见论坛帖子:
http://www.jyguagua.com/bbs/forum.php?mod=viewthread&tid=17&fromuid=1
make命令在执行是,需要在当前目录中找到一个Makefile的文件或者makefile的文件,如果makefile文件不是Makefile或者makefile,那么执行的时候,需要这么执行:
make -f 文件名
Makefile的规则,知道了这个规则,就能自己写出一些Makefile,Makefile的规则如下:
另外,有一些符号,我们也需要掌握:
根据综上,我们可以写一个小小的例子:
hello.c内容如下:
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("hello, world!\n");
return 0;
}
Makefile的内容如下:
hello : hello.o
gcc $^ -o $@
hello.o : hello.c
gcc -c $^
clean:
rm -rf hello.o hello
我们要清理生成的obj文件还有可执行文件,执行:
make clean
如果我们需要编译链接生成可执行文件,执行:
make
然后我们执行:
./hello
文章的脚注信息由WordPress的wp-posturl插件自动生成


微信扫一扫,打赏作者吧~


![[已解决]nc命令报错 close: Bad file descriptor](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2022/03/Snipaste_2022-03-18_20-16-48.png&w=280&h=210&zc=1)