Home > Blockchain >  Makefile not detecting changes to source file when running make
Makefile not detecting changes to source file when running make

Time:12-17

Issue Description

I have a Makefile that is not recognizing when changes to the underlying source code are made. When I attempt a build I get the following message to the console: "make: Nothing to be done for 'all'." My sense is that this probably has to do with a flawed understanding on my part regarding how to work with files in different directories. I have seen similar questions on StackOverflow but none seem to deal quite with this issue or the issue appears to result from other problems.

Project Structure

src: the source code files live here.

include: header files live here.

build: object files live here.

bin: executables live here.

test: test code lives here.

Makefile: the make file.

Makefiles

I have created a basic source file called main.c and placed it in src and implemented a simple make file as follows:

CC = gcc
CFLAGS = -DTESTABLE -Wall -std=c99 -g

all: bin/main

bin/main: build/main.o
build/main.o: src/main.c

clean:
    rm -f build/main.o
    rm -f bin/main

Source File

#include <stdio.h>

int main( int argc, char *argv[] )
{
    printf( "Hi there. For real." );
}

CodePudding user response:

These lines:

bin/main: build/main.o
build/main.o: src/main.c

tell make that to build bin/main it needs build/main.o and to build build/main.o it needs src/main.c, but you haven't actually told make how to build either build/main.o or bin/main. You have to provide a recipe that make can use to actually do the build; maybe:

bin/main: build/main.o
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
build/main.o: src/main.c
        $(CC) $(CFLAGS) -c -o $@ $<
  • Related