0
votes

This is my first attempt to create a make-file for compiling. I'm working on a project where I want to divide files under compiling, sow i have 3 folders: src, bin and header. Today I compile with the command gcc file1.c file2.c file3.c -lncurses

How can I write a makefile to achieve this ?

1

1 Answers

0
votes

This will do it:

bin/myBinaryName: file1.c file2.c file3.c
    gcc $^ -Iheader -lncurses -o $@

vpath %.c src

There are more sophisticated approaches than this, but I suspect that you are taking the same course as the other newcomers who have asked very similar questions over the past couple of weeks.

If you want a more basic introduction, or a more sophisticated makefile, you can try a different question.

EDIT:

Let's try something simpler. Write this makefile (and name it makefile):

all:
    echo hello world

Note that the whitespace before "echo" is a TAB. Now try make on the command line. What happens?