簡體   English   中英

如何使用帶有Codeblocks的makefile

[英]How use a makefile with Codeblocks

當我使用Codeblocks創建和添加makefile項目時,我遇到了一些問題。 我創建了一個包含3個文件的項目: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

和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

我勾選這是一個自定義的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))

如何在編碼塊中使用makefile?

當您從codeblock內部運行構建時(無論是什么),它使用參數-f Makefile (多余但不會受到傷害)和Debug調用make,這意味着它要構建一個名為Debug的目標。

但是你的makefile沒有定義任何名為Debug目標,所以你得到了你看到的錯誤。

修改makefile並定義名為Debug的目標:

Debug: all

或者弄清楚如何讓codeblock調用make使用不同的參數,因此它在命令行上沒有Debug

Codeblock在構建項目的makefile中需要一個名為“Debug:”的Target。

正確設置之后問題的另一部分是獲取代碼塊以在調試器下運行程序。 單擊“紅色播放按鈕”的示例,而不僅僅是齒輪按鈕。 要設置它:

確保-g在makefile中指定為gcc或g ++。

使用“Project-> Properties-> Build targets-> Output filename”指定Makefile生成的可執行文件的名稱。

使用“Project-> Set programs arguments”將命令行參數設置為程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM