Search code examples
cmakefilesdlubuntu-15.04

Makefile C with SDL2


I was given program written in C using SDL2 and nasm. I have problem with makefile: "*** Nor rule to make target'../home/amellana/Desktop/project/main.c', needed by 'main.o'" Does anybody know what to change in my makefile?

CC=gcc
CFLAGS=-Wall -Wextra

ASM=nasm
AFLAGS=-f elf64

all: myfunc mytest

main.o: ../home/amellana/Desktop/project/main.c  
    $(CC) $(CFLAGS) -c ../home/amellana/Desktop/project/main.c
mytest.o: ../home/amellana/Desktop/project/mytest.c
$(CC) $(CFLAGS) -c ../home/amellana/Desktop/project/mytest.c
program.o: program.nasm
    $(ASM) $(AFLAGS) program.nasm
myfunc: main.o myfunc.o
    $(CC) $(CFLAGS) main.o program.o -lSDL2 -o myfunc
mytest: mytest.o program.o
    $(CC) $(CFLAGS) mytest.o program.o -o mytest
clean:
    rm -f *.o
    rm -f myfunc
    rm -f mytest

Solution

  • The general syntax for Makefile rules is:

    <target>: <dependencies>
        <recipe>
    

    In your case, this part:

    main.o: ../home/amellana/Desktop/ARKO/main.c
        $(CC) $(CFLAGS) -c ../home/amellana/Desktop/project/main.c
    

    means that in order to create target main.o, dependency ../home/amellana/Desktop/ARKO/main.c must be built first. The file doesn't exist, and there is no rule defined for such a target. So, the dependency fails.

    You probably have misspelled the filename, or the path is not correct.