从 C 程序制作命令行工具
如果我想使用 makefile 创建一个命令行工具,请说这个 C 程序:
# include<stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
我以前没有任何 makefile 或 linux shell 命令的经验。刚刚开始。谁能告诉我该怎么做?
If I want to make a commandline tool using makefile for, say this C program:
# include<stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
I have no previous experience with makefile or linux shell commands whatsoever. Just starting out. Can anyone tell me how to go about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于像这样的单个源文件,您实际上并不需要 makefile - 只需像这样编译它:
如果您确实想要一个 makefile,那么您可以这样做:
然后从命令行您可以说:
或者甚至只是
You don't really need a makefile for a single source file like this - just compile it like this:
If you really want a makefile though then you can do something like this:
then from the command line you could say:
or even just
我手头没有 Unix 盒子,但是 make(1) 的 ISTR 有一些默认规则,应该允许您简单地输入
make hello
,它会找到 hello.c 并生成一个名为 ' 的二进制文件你好'。当然,对于更复杂的事情,您需要阅读 make(1) 或其后代,man make
是一个很好的起点。I don't have a Unix box handy, but ISTR that make(1) has some default rules that should allow you to simply type
make hello
and it will find hello.c and generate a binary named 'hello'. Of course, for anything more complicated, you'll want to read up on make(1) or its descendents,man make
is a good place to start.Makefile:
您可能会受益于这个。
另外,您的程序缺少换行符。您可能想打印
“Hello World!\n”
。Makefile:
You might benefit from this.
Also, your program is missing a newline. You probably wanted to print
"Hello World!\n"
.