windenergy
windenergy

Reputation: 391

Makefile variable issue, make wants to create "*.o" instead of foo.o bar.o etc

I thought this would be simple but I can not get it to work. When I run the command

make --dry-run

On this makefile:

CC = g++
CFLAGS = -std=c++11
SRCS = *.cpp
OBJS = (SRCS:.cpp=.o)

testprogram: $(OBJS)
  $(CC) $(CFLAGS) -o $@ $(OBJS)

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

I would expect it to be processing the compilation line in the form:

g++ -c -std=c++11 foo.cpp -o foo.o

However, it is showing this command:

g++ -c std=c++11 foo.cpp -o *.o

So, it is trying to create a file "*.o" instead of the desired object file target. What has gone wrong here?

Upvotes: 1

Views: 54

Answers (1)

windenergy
windenergy

Reputation: 391

Ok thanks to the comment of @Juanchopanza, I have seen my mistake.

The third line needs to become:

SRCS = $(wildcard *.cpp)

A simple SRCS = *.cpp is not correct

Upvotes: 3

Related Questions