'$< in makefile seems to give empty output
I'm trying to write a makefile for my test C++ project that works with separate directories for source code and object files. I followed an answer to another question on StackOverflow (which I sadly can't find anymore), but I must've done something wrong.
My makefile looks like this:
INCLUDE=-I /usr/include/boost/
LIBDIR=-L /usr/lib/x86_64-linux-gnu/
LIBS=-lboost_date_time
SOURCES=$(wildcard src/*.cpp)
OBJDIR=obj/
OBJECTS=$(patsubst %.cpp, %.o, $(SOURCES))
a.out: $(OBJECTS)
g++ $(LIBDIR) $(LIBS) $(OBJECTS)
$(OBJECTS): obj/%.o : src/%.cpp
g++ $(INCLUDE) -c $< -o $@
clean:
rm obj/*.o
cleanall:
rm obj/*.o a.out
And here is the project directory:
~/Programming/testing-cpp
❯ tree
.
├── makefile
├── obj/
└── src/
├── main.cpp
├── message.cpp
└── message.h
2 directories, 5 files
When i try to run make, I get this:
~/Programming/testing-cpp
❯ make
makefile:25: target 'src/message.o' doesn't match the target pattern
makefile:25: target 'src/main.o' doesn't match the target pattern
g++ -I /usr/include/boost/ -c -o src/message.o
g++: fatal error: no input files
compilation terminated.
make: *** [makefile:26: src/message.o] Error 1
From the line that reads g++ -I /usr/include/boost/ -c -o src/message.o it seems that $< is giving me an empty output. Why is this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
