makefile Recipe for target failed in Dev C++ - dev-c++

I am using Dev C++ v5.5.3
I have just written the code for the program and the makefile was generated by Dev C++.
I don't know anything about Makefiles. Here is the makefile generated by Dev C++.
I keep getting the error "recipe for target 'Dialogs_Private.res' failed".
Please help
# Project: Dialogs
# Makefile created by Dev-C++ 5.5.3
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES = Dialogs_private.res
OBJ = Main.o $(RES)
LINKOBJ = Main.o $(RES)
LIBS = -L"C:/Program Files/Dev-Cpp/MinGW32/lib" -static-libstdc++ -static-libgcc
INCS = -I"C:/Program Files/Dev-Cpp/MinGW32/include"
CXXINCS = -I"C:/Program Files/Dev-Cpp/MinGW32/include"
BIN = Dialogs.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)
Main.o: Main.cpp
$(CPP) -c Main.cpp -o Main.o $(CXXFLAGS)
Dialogs_private.res: Dialogs_private.rc dialogResource.rc
$(WINDRES) -i Dialogs_private.rc --input-format=rc -o Dialogs_private.res -O coff

From your generated makefile we can find you are using your own resource script.
Dialogs_private.res: Dialogs_private.rc dialogResource.rc
DevC++ will generate a resource script(ProjectName_private.rc, in your case, is Dialogs_private.rc) and make a resource file(ProjectName_private.res) via that script. in your case, this generated Dialogs_private.rc file may like this:
/* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
/* DO NOT EDIT! */
#include "dialogResource.rc"
As you can see, it just included your dialogResource.rc. DevC++ will try to compile it. if your resource script have some error, then it can not be compiled. Then you will see an error that tell you recipe for target 'Dialogs_Private.res' failed .
You should check your own resource script and have a look if there is any error in your script file. For example, are you missing some resource you are going to compile but you forget to place the resource file to the correct path? After all your own resource script compiled successfully, this error will be fixed.

Related

SFML library doesn't link with makefile compilation

I have been trying to link the SFML dlls to my windows C++ project, but I can't get it to work. I always end up with:
fatal error: SFML/System.hpp: No such file or directory
I've tried a bunch of things but nothing changes the issue.
Here is my makefile:
PROGRAM = zero_flip
OBJS = src/main.o src/Math.o src/card.o src/game_board.o src/indicator.o src/ui.o
CXX = g++
CXX_FLAGS = -O0 -g -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable
LIB_DIRS = -L./Resources/libs/
LIBS = -lsfml-system -lsfml-graphics -lsfml-window -lsfml-audio
LNK_FLAGS = $(LIB_DIRS) $(LIBS)
DEPS=$(OBJS:.o=.d)
.PHONY: all clean
all: $(PROGRAM)
-include $(DEPS)
%.o: %.cpp
$(CXX) $(CXX_FLAGS) $(LNK_FLAGS) $< -o $#
$(PROGRAM): $(OBJS)
$(CXX) $(CXX_FLAGS) $(LNK_FLAGS) $^ -o $#
clean:
rm -f $(OBJS) $(DEPS) $(PROGRAM) && clear
The "./Resources/libs/" directory contains:
openal32.dll
sfml-audio-2.dll
sfml-audio-d-2.dll
sfml-graphics-2.dll
sfml-graphics-d-2.dll
sfml-system-2.dll
sfml-system-d-2.dll
sfml-window-2.dll
sfml-window-d-2.dll
Can anyone get me unstuck please this is driving me mad.
This is wrong:
%.o: %.cpp
$(CXX) $(CXX_FLAGS) $(LNK_FLAGS) $< -o $#
This rule says it will compile a source file into an object file, but the recipe actually builds a complete executable: it will compile the source file like xxx.cpp then link it into a program named xxx.o. You need to invoke just the compiler here, not the linker, so you should not have $(LNK_FLAGS) and you need to add the -c option to tell the compiler to stop after compiling and not link.
Then you need to add an -I option to the compile line telling the compiler where to find the header files needed during compilation... in this case SFML/System.hpp.

Dev c++ mingw no longer compiles

I'm using Dev C++ 4.9.9.2 and my programs stopped compiling since yesterday.
My compiler error just looks like this:
F:\Program\Makefile.win [Build Error] [Program.exe] Error 1
With the compile log messages being:
Compiler: Default compiler
Building Makefile: "F:\Program\Makefile.win"
Executing make...
make.exe -f "F:\Program\Makefile.win" all
gcc.exe Untitled1.o -o "Program.exe" -L"F:/Dev-Cpp/lib"
gcc.exe: Internal error: Aborted (program collect2)
Please submit a full bug report.
See <URL:http://www.mingw.org/bugs.shtml> for instructions.
make.exe: *** [Program.exe] Error 1
Execution terminated
And this is my makefile for a newly made project:
# Project: Program
# Makefile created by Dev-C++ 4.9.9.2
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES =
OBJ = main.o $(RES)
LINKOBJ = main.o $(RES)
LIBS = -L"F:/Dev-Cpp/lib"
INCS = -I"F:/Dev-Cpp/include"
CXXINCS = -I"F:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"F:/Dev-Cpp/include/c++/3.4.2/backward" -I"F:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"F:/Dev-Cpp/include/c++/3.4.2" -I"F:/Dev-Cpp/include"
BIN = Program.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before Program.exe all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "Program.exe" $(LIBS)
main.o: main.cpp
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)
I've tried reinstalling mingw and linking a new compiler profile to it, and I've also tried reinstalling Dev C++ but this problem persists.
Both new projects and old projects that have previously compiled fine no longer compile...
Has anyone had any similar issues?
Something with the linker refused to work for me.
I installed mingw using TDM-GCC and made a new compiler profile for that, which ended up working.
I'm still at a loss for why the included mingw suddenly stopped working and didnt work properly even after reinstalling.

How to make an object file in a different folder with c++ and a makefile

When I run my code I get the error
g++ -c -o main.o main.cpp
g++ -I -o obj/main.o -lm
g++ error: obj/main.o: No such file or directory
makefile:21: recipe for target 'main' failed
make: *** [main] Error 1
In my file structure I have a folder with everything in it so I am trying to make some subdirectories and organize everything a little bit. I am trying to get the object file (main.o) to go into an obj folder instead of staying in the base folder as it currently is.
I can't figure out what is going wrong in my makefile and can't find where some of this is being executed and am extremely new to c++ and make. My code is pasted below.
IDIR=../include
CC = g++
CFLAGS = -I
LDIR = ../lib
ODIR= obj
LIBS = -lm
_DEPS = add.h multiply.h
DEPS = $(patsubst %, $(IDIR)/%,$(_DEPS))
_OBJ = main.o
OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: $(OBJ)
$(CC) -c $(CFLAGS) $< -o $#
main: $(_OBJ)
$(CC) $(CFLAGS) -o$(OBJ) $(LIBS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
I haven't read any specific documentation as I have been teaching myself by simply searching the internet for tons of small bits from many different sources. I am using Windows 10 with visual studio code as my compiler and make g++ as my make utility. I apologize for commenting on my own question as this is my first time using Stack Overflow and didn't know I could get in trouble for commenting. I am sorry for causing a mess.
g++ -c -o obj/main.o main.cpp
you must provide the path for the output file

adding a resource file manually in Dev-Cpp

I am making a simple Win32 C++ game and when I made a header file and a resource file once I compiled it I had an error message from the compile log wich said "*** missing separator. stop"and it was from the make file in the line that had my new resource file.
This is not the first time I try to make a resource file as I did it with another simple apps and it worked fine but now with this application it didnt work also I checked the makefile from another aplication and they had the same syntax.
Any help would be appreciated.
And by the way im using Dev-Cpp ide and compiler if that may help you find a solution for my problem.
**Edit:**The makefile code is:
# Project: Win32 Game 1
# Makefile created by Dev-C++ 4.9.9.2
CPP = g++.exe -D__DEBUG__
CC = gcc.exe -D__DEBUG__
WINDRES = windres.exe
RES = Win32_Game_#1_private.res
OBJ = WinMain.o $(RES)
LINKOBJ = WinMain.o $(RES)
LIBS = -L"C:/Dev-Cpp/lib" -mwindows -lgmon -pg -g3
INCS = -I"C:/Dev-Cpp/include"
CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
BIN = "Win32 Game 1.exe"
CXXFLAGS = $(CXXINCS) -pg -g3
CFLAGS = $(INCS) -pg -g3
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before "Win32 Game 1.exe" all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "Win32 Game 1.exe" $(LIBS)
WinMain.o: WinMain.cpp
$(CPP) -c WinMain.cpp -o WinMain.o $(CXXFLAGS)
Win32_Game_#1_private.res: Win32_Game_#1_private.rc Settings.rc
$(WINDRES) -i Win32_Game_#1_private.rc --input-format=rc -o Win32_Game_#1_private.res -O coff
Settings.rc is the resource file that im trying to add

Makefile directories error

Im using this code in the makefile, all is going good but the last line.
My code folder looks like this:
Project/bin -> For executable files
Project/build -> For .o files
Project/include -> For .hpp files
Project/src -> For .cpp files
Makefile path: Project/Makefile
# Compiler #
CC = g++
DEBUG = -g
LFLAGS =
CFLAGS = -Wall
# Directories #
SRCDIR = src/
INCDIR = include/
BUILDDIR = build/
BINDIR = bin/
# Objects #
OBJ_NAMES = main.o dfa.o dfaException.o state.o
OBJS = $(addprefix $(BUILDDIR), $(OBJ_NAMES))
# Output #
TARGET = $(BINDIR)pract3
$(TARGET): $(OBJS)
$(CC) $(CCFLAGS) $(LFLAGS) $(OBJS) -o $(TARGET)
$(BUILDDIR)%.o: $(SRCDIR)%.cpp
$(CC) $(CCFLAGS) $(LFLAGS) -c $< -o $(BUILDDIR)$($(notdir $<):.cpp=.o)
The problem is in "$(BUILDDIR)$($(notdir $<):.cpp=.o)". What Im trying to do here is:
$< contains "src/mysrc.cpp" so with $(notdir $<) I get
"mysrc.cpp"
Now, I want to change the file extension to .o, so I use $($(notdir $<):.cpp=.o) And I should get "mysrc.o". But this part is not working:
g++ -c src/main.cpp -o build/
Assembler messages:
Fatal error: can't create build/: Permission denied
Makefile:25: recipe for target 'build/main.o' failed
make: *** [build/main.o] Error 1
I use $(BUILDDIR) To get "build/mysrc.o"
Why does $($(notdir $<):.cpp=.o) somehow delete the file name ?
And now that Im here. I've learned to use make some days ago. Is there something that I should improve here ?
$(notdir) operates on strings.
$(X:Y=Z) operates on the value of the X variable.
So follow your expansions when $< is src/mysrc.cpp
$($(notdir $<):.cpp=.o)
becomes
$(mysrc.cpp:.cpp=.o)
Is that how you would write that?
No, you would write $(<:.cpp=.o).
So invert your operations.
$(notdir $(<:.cpp=.o))
Or, even better and simpler than that just use $# since that's the target you are building and what you want to create.
$(CC) $(CCFLAGS) $(LFLAGS) -c $< -o $#