从C程序制作命令行工具

pra*_*ful 3 c makefile command-line-tool

如果我想使用makefile创建一个命令行工具,比如这个C程序:

# include<stdio.h>

int main()
{
    printf("Hello World!");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我以前没有使用makefile或linux shell命令的经验.刚开始.谁能告诉我怎么去呢?

Pau*_*l R 6

你真的不需要像这样的单个源文件的makefile - 只需像这样编译它:

$ gcc -Wall foo.c -o foo
Run Code Online (Sandbox Code Playgroud)

如果你真的想要一个makefile,那么你可以这样做:

#
# makefile
#

foo: foo.c
    gcc -Wall foo.c -o foo
Run Code Online (Sandbox Code Playgroud)

然后从命令行你可以说:

$ make foo
Run Code Online (Sandbox Code Playgroud)

甚至只是

$ make
Run Code Online (Sandbox Code Playgroud)