2014-12-07 504 views
0

我想在dev C++ 5.7.1中使用graphics.h。graphics.h在dev C++中不工作

我已經在網上搜索了可用選項。 我下載的包括文件夾中的graphics.h中庫,並選擇在參數選項如下:

-lbgi 
-lgdi32 
-lcomdlg32 
-luuid 
-loleaut32 
-lole32 

我仍然想不通爲什麼它顯示我這些錯誤:

undefined reference to `initgraph' 
undefined reference to `graphresult' 
undefined reference to `grapherrormsg' 
undefined reference to `getmaxx' 
undefined reference to `getmaxy' 
undefined reference to `getmaxcolor' 
undefined reference to `getcolor' 
undefined reference to `circle' 
undefined reference to `closegraph' 
[Error] ld returned 1 exit status. 

這是我的代碼:

#include<iostream> 
#include<graphics.h> 
#include<stdlib.h> 
#include<stdio.h> 
//#include<conio> 
int main(void) 
{ 
     /* request auto detection */ 
     int gdriver = DETECT, gmode, errorcode; 
     int midx, midy; 
     int radius = 100; 
     /* initialize graphics and local variables */ 
     initgraph(&gdriver, &gmode, "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\include\\winbgim"); 
     /* read result of initialization */ 
     errorcode = graphresult(); 
     if (errorcode != grOk) /* an error occurred */ 
     { 
      printf("Graphics error: %s\n", grapherrormsg(errorcode)); 
     printf("Press any key to halt:"); 
     getch(); 
     exit(1); /* terminate with an error code */ 
    } 
    midx = getmaxx()/2; 
    midy = getmaxy()/2; 
    setcolor(getmaxcolor()); 
    /* draw the circle */ 
    circle(midx, midy, radius); 
    /* clean up */ 
    getch(); 
    closegraph(); 
    return 0; 
} 
+0

我假設你使用[WinBGIm](http://winbgim.codecutter.org/)。您是否按照安裝說明將libbgi.a文件放入庫目錄中? – 2014-12-07 09:43:53

+0

是的,我正確地按照所有的安裝說明進行操作。所有的文件都放置在應有的位置。 – 2014-12-07 10:29:38

+0

@AvniSingh你有使用'Dev-C++'的具體要求嗎?如果沒有,我建議去'SFML',因爲它提供了比'Dev-C++'更多的***功能。 *哦,是的,你也可以很容易地在其中繪製圓圈。* – cybermonkey 2014-12-07 11:20:41

回答

0

錯誤消息表明函數未定義。函數通常在源代碼或庫(靜態或動態)中定義。因此,您需要將源代碼包含在項目中,以便與上面的代碼鏈接,或者需要鏈接到預編譯的庫(也許是.a,.lib或.dll文件)。

我對您使用的庫不太熟悉;但是,我會假設graphics.h包含函數聲明,並且不包含函數定義。

+0

我檢查了graphics.h的代碼。你是對的。它只包含函數聲明而不包含函數定義。爲了糾正這個問題,你會建議什麼?問題? – 2014-12-07 10:27:08

2

下載以下文件中提到的目錄:

在這裏,我假設你安裝了開發-CPP到C:\Dev-Cpp

http://www.cs.colorado.edu/~main/bgi/dev-c++/graphics.h目錄:> C:\開發-CPP \包括 http://www.cs.colorado.edu/~main/bgi/dev-c++/libbgi.a目錄:>Ç :\開發-CPP \ lib中

創建一個新的C++項目,並設置 「項目選項 - >參數 - >鏈接」 爲

-lbgi 
-lgdi32 
-lcomdlg32 
-luuid 
-loleaut32 
-lole32 

並嘗試執行此示例代碼;然後去找你上面發佈的代碼。

#include<graphics.h> 

int main(){ 
     initwindow(700 , 700 , "MY First Program"); 
     circle(200, 200, 150); 
     getch(); 
     return 0; 
} 
+0

我已經嘗試了上面提到的。這些文件在提到的目錄中。我試着運行你的代碼。它仍然顯示相同的錯誤: – 2014-12-07 10:20:06

0

這是鏈接錯誤。確保你在項目選項 - >參數 - >鏈接器中寫入的庫名稱以「-」開頭。

-lbgi 
-lgdi32 
-lcomdlg32 
-luuid 
-loleaut32 
-lole32 

as Zeke上面寫的。

相關問題