Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Not sure what's wrong with this makefile?

CGLAGS= -std=c++17 -I. -I$(VULKAN_SDK_PATH)/include
LDFLAGS = -L$(VULKAN_SDK_PATH)/lib `pkg-config --static --libs glfw3` -lvulkan
OUTPUT_DIR = ./bin

a.out: *.cpp *.hpp
    g++ $(CFLAGS) -o $(OUTPUT_DIR)/a.out *.cpp $(LDFLAGS)

.PHONY: test clean

test: a.out
    ./a.out
clean:
    rm -f $(OUTPUT_DIR)/a.out

This is the error I’m getting

make: *** No rule to make target `*.hpp', needed by `a.out'.  Stop.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

make is interpreting *.hpp as a file name, not a glob. This is because either

  1. there is no file matching *.hpp in the working directory, or
  2. this make does not recognize glob patterns in the first place,

or both.

Note well that POSIX does not specify that wildcards should be recognized in target and prerequisite names, and many make‘s indeed don’t recognize them. Accordingly, using wildcards in targets and prerequisites is poor style.

Conventionally, you would explicitly list all the relevant filenames in your makefile, possibly in the value of a variable instead of directly in the rule. This has considerable advantages, and generally is not onerous.

If you happen to be using GNU make, and are willing to be dependent on that particular flavor, then you should probably use its $(wildcard) function to expand globs instead of using them directly in rule targets or prerequisites.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading