-2

I have a basic Makefile setup for C OpenGL programming but when running there are 2 files passed to clang that shouldnt exist and i have no idea why. The problem happened after i added glad and glfw to the project.

code:

    CC = clang
    `CCFLAGS = -lGL -lglfw -std=c++20 -v -Wall -Wextra -Wepedantic -g -lgdi32
    LDFLAGS = lib/glad/src/glad.o lib/glfw/src/libglfw3.a -lgdi32 -lm 
    SRC = $(wildcard src/*.c)
    OBJ  = $(SRC:.c=.o)
    BIN = bin

all: libs build

libs:
    cd lib/glad && $(CC) -o src/glad.o -Iinclude -c src/glad.c
    cd lib/glfw && cmake . -G 'Unix Makefiles' && make

build: $(OBJ)
    $(CC) -o $(BIN)/build $^ $(LDFLAGS)

%.o %.c:
    $(CC) -o $@ -c $< $(CCFLAGS)

run:
    ./bin/build.exe

ERROR: clang: error: no such file or directory: 'all.o' clang: error: no such file or directory: 'libs' clang: error: no such file or directory: 'build'

  • 3
    Please read [Discourage screenshots of code and/or errors](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) and paste the code in the question. – Rabbid76 Jan 07 '23 at 22:51
  • Welcome! Can you please provide a [mre]? See [ask] for further guidance on asking questions. Please [edit] to convert your images of text into actual text. [See here](https://meta.stackoverflow.com/a/285557/11107541) for why. See [/editing-help](/editing-help#code) for how to format code blocks. As long as you follow the guidance in ["What is the proper way to approach Stack Overflow as someone totally new to programming?"](https://meta.stackoverflow.com/q/254572/11107541), then [you don't need to tell us that you are new to `X`](https://meta.stackoverflow.com/q/296391/11107541). – starball Jan 08 '23 at 08:37
  • CCFLAGS is preceded by a spurious quote. – stark Jan 08 '23 at 12:11

1 Answers1

1

When asking questions please include the command you typed, the command make printed, plus at least the first and last few lines of error messages (properly formatted as code blocks).

I'm assuming that the extra quote character is an error in your cut and paste; please take a moment to review your question after you post it (or even better, using the preview before you post it). You are writing this one time, but tens or hundreds of people will spend their time reading it. Please be considerate enough to make it easy for them.

Your problem is this:

%.o %.c:
        $(CC) -o $@ -c $< $(CCFLAGS)

You want to say "build a .o file from a .c file using this rule", but %.o %.c: says instead, "build both a .o and a .c file, from nothing, using this rule".

You need:

%.o: %.c
        $(CC) -o $@ -c $< $(CCFLAGS)
MadScientist
  • 92,819
  • 9
  • 109
  • 136