There is such a makefile:

CXX := mingw32-g++ LINK := mingw32-g++ INCLUDE := -I"../usr/include" CXX_FLAGS := -std=c++1y -DDEBUG -g -O0 -Wall -c -fmessage-length=0 $(INCLUDE) RM := rm -rf LIBS_DIR := -L"../usr/lib/" LIBS := -lDekaLib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf CPP_SRCS := $(wildcard ../src/*.cpp) $(wildcard ../src/**/*.cpp) OBJS := $(CPP_SRCS:.cpp=.o) all: ADG.exe %.o : %.cpp @echo 'Building $<' $(CXX) $(CXX_FLAGS) -o "$@" "$<" @echo 'Finished building $<' ADG.exe: ../Debug ../Debug/resources $(OBJS) @echo 'Building target: $@' $(LINK) $(LIBS_DIR) -o "../Debug/ADG.exe" $(OBJS) $(LIBS) cp -r ../resources/* "../Debug/resources" cp -r ../usr/bin/* "../Debug" @echo 'Finished building target: $@' @echo ' ' clean: $(RM) $(OBJS) "../Debug" ../Debug: mkdir ../Debug ../Debug/resources: mkdir ../Debug/resources 

It is working, but it creates object files in the source folder. How do I make the object files in the same folder as the makefile?

  • 1. creates not a file, or even the make program, but the mingw32-g ++ program it calls . 2. what you want to do, firstly, is meaningless , and secondly, in addition to being very difficult to implement, even if the file names coincide, it will simply lead to inoperability. 3. If for some reason you are not satisfied with the availability of obi-files, you can delete them (or move them where you need) after compilation. // I highlighted the most important word in bold. - aleksandr barakin

1 answer 1

Your makefile can be added, the object files will be created in a separate obj directory

 CXX := mingw32-g++ LINK := mingw32-g++ INCLUDE := -I"../usr/include" CXX_FLAGS := -std=c++1y -DDEBUG -g -O0 -Wall -c -fmessage-length=0 $(INCLUDE) RM := rm -rf LIBS_DIR := -L"../usr/lib/" LIBS := -lDekaLib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf CPP_SRCS := $(wildcard ../src/*.cpp) $(wildcard ../src/**/*.cpp) OBJS := $(patsubst ../src/%.c,obj/%.o,$(CPP_SCRC)) all: ADG.exe obj/%.o : %.cpp @echo 'Building $<' $(CXX) $(CXX_FLAGS) -o "$@" "$<" @echo 'Finished building $<'