Makefile include sources and object files from other directory
I have a small project where the directory structure looks like this:
.
|-- common
| |-- tile.cpp
| `-- tile.hpp
|-- editor
| |-- Makefile
| `-- main.cpp
`-- game
|-- Makefile
`-- main.cpp
I'm trying to configure the Makefiles so that everything in the own subdirectory is compiled and linked to, as well as everything in the common directory. This is my attempt:
CC = g++
CMN_DIR = ../common
CFLAGS = -c -I..
SRCS := $(wildcard *.cpp $(CMN_DIR)/*.cpp)
OBJS := $(SRCS:cpp=o)
all: $(OBJS)
$(CC) -o $@ $(OBJS)
$(OBJS): %.o: %.cpp
$(CC) -c $< $(CFLAGS)
The problem is that object files get created in the current subdirectory, but we are searching for them in the common directory, where they are supposed to be.
g++: error: ../common/tile.o: No such file or directory
How to configure the Makefile so that we output the common object files in the common directory?
.
|-- common
| |-- tile.cpp
| `-- tile.hpp
|-- editor
| |-- Makefile
| `-- main.cpp
`-- game
|-- Makefile
`-- main.cpp
I'm trying to configure the Makefiles so that everything in the own subdirectory is compiled and linked to, as well as everything in the common directory. This is my attempt:
CC = g++
CMN_DIR = ../common
CFLAGS = -c -I..
SRCS := $(wildcard *.cpp $(CMN_DIR)/*.cpp)
OBJS := $(SRCS:cpp=o)
all: $(OBJS)
$(CC) -o $@ $(OBJS)
$(OBJS): %.o: %.cpp
$(CC) -c $< $(CFLAGS)
The problem is that object files get created in the current subdirectory, but we are searching for them in the common directory, where they are supposed to be.
g++: error: ../common/tile.o: No such file or directory
How to configure the Makefile so that we output the common object files in the common directory?
Комментарии
Отправить комментарий