I have some problems when I create and add a makefile project with Codeblocks. I created a project which has 3 files: main.cpp; View.cpp; View.h.
main.cpp:
#include <iostream>
#include "View.h"
using namespace std;
int main(int argc, char** argv) {
View view;
view.box();
}
View.cpp:
#include <iostream>
#include "View.h"
using namespace std;
void View::box()
{
int i=3;
switch(i)
{
case 1:
break;
case 2:
break;
case 3:
break;
}
cout<<"AAAA";
};
View.h:
#ifndef VIEW_H_INCLUDED
#define VIEW_H_INCLUDED
class View
{
//// ****************************
//// ---------------------------
//// ---------------------------
public :
void box();
//// ****************************
};
#endif
And Makefile:
all : lienket
lk : main.o View.o
g++ main.o View.o -o lienket
main.o : main.cpp
g++ -c main.cpp
View.o : View.cpp
g++ -c View.cpp
I ticked this is as a custom Makefile.(Project->properties->Project setting)
Finally I build but receive the following error:
-------------- Build: Debug in lienket (compiler: GNU GCC Compiler)---------------
Running command: mingw32-make.exe -f Makefile Debug
mingw32-make.exe: *** No rule to make target `Debug'. Stop.
Process terminated with status 2 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
How do I use a makefile with Codeblocks?
When you run the build from inside codeblock
(whatever that is), it's invoking make with the arguments -f Makefile
(which is redundant but doesn't hurt) and Debug
, which means that it wants to build a target named Debug
.
But your makefile doesn't define any target named Debug
, so you get the error you see.
Either modify your makefile and define a target named Debug
:
Debug: all
Or else figure out how to have codeblock
invoke make with different arguments so it doesn't have Debug
on the command line.
Codeblock requires a Target Named "Debug:" in the makefile that builds your project.
The other part of the problem after setting this up corretly is getting codeblock to run the program under the debugger. Example clicking the "red play button", not just the gear button. To set that up:
sure -g is specified to gcc or g++ in your makefile.
Use "Project->Properties-> Build targets->Output filename" to specify the name of the executable generated by your Makefile.
Use "Project->Set programs arguments" to set the command-line parameters to the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With