如何在代码块中使用 makefile

use*_*073 5 c++ makefile codeblocks

我在使用 Codeblocks 创建和添加 makefile 项目时遇到了一些问题。我创建了一个包含 3 个文件的项目: main.cpp; 查看.cpp; 查看.h.

主.cpp:

#include <iostream>
#include "View.h"
using namespace std;
int main(int argc, char** argv) {
    View view;
    view.box();
}
Run Code Online (Sandbox Code Playgroud)

查看.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";


};
Run Code Online (Sandbox Code Playgroud)

查看.h:

#ifndef VIEW_H_INCLUDED
#define VIEW_H_INCLUDED

class View
{
//// ****************************

//// ---------------------------


//// ---------------------------

public :

void box();


//// ****************************
};

#endif
Run Code Online (Sandbox Code Playgroud)

和 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
Run Code Online (Sandbox Code Playgroud)

我勾选这是作为自定义 Makefile。(项目-> 属性-> 项目设置)

最后我构建但收到以下错误:

-------------- 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))
Run Code Online (Sandbox Code Playgroud)

如何在代码块中使用 makefile?

Mad*_*ist 5

当您从内部运行构建codeblock(无论是什么)时,它会使用参数-f Makefile(这是多余的,但不会造成伤害)和调用 make Debug,这意味着它想要构建一个名为 的目标Debug

但是您的 makefile 没有定义任何名为 的目标Debug,因此您会收到所看到的错误。

修改您的 makefile 并定义名为的目标Debug

Debug: all
Run Code Online (Sandbox Code Playgroud)

或者弄清楚如何使用codeblock不同的参数调用 make ,这样它就不会出现Debug在命令行上。

  • 我不明白你的评论。 (3认同)