Search code examples
cmakefilecommand-line-tool

Make a commandline tool from C program


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?


Solution

  • You don't really need a makefile for a single source file like this - just compile it like this:

    $ gcc -Wall foo.c -o foo
    

    If you really want a makefile though then you can do something like this:

    #
    # makefile
    #
    
    foo: foo.c
        gcc -Wall foo.c -o foo
    

    then from the command line you could say:

    $ make foo
    

    or even just

    $ make