Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Undefined Reference To 'initgraph'(Graphics Program In C++ Not Getting Executed Via Eclipse)
Undefined Reference To 'initgraph' [message #1806592] Sat, 11 May 2019 07:42 Go to next message
Mukesh Lekhrajani is currently offline Mukesh LekhrajaniFriend
Messages: 12
Registered: May 2018
Junior Member
My Code -

#include <iostream>
#include <winbgim.h>
#include <cstdlib>
#include "graphics.h"

using namespace std;

int main()
{
int gdriver = 9;
int gmode = 2;
initgraph(&gdriver,&gmode, "");
setbkcolor(WHITE);
setcolor(BLACK);
cleardevice();
circle(320,240,180);
getch();
closegraph();
return 0;
}


The Error -

12:53:49 **** Incremental Build of configuration Debug for project My_CPP_World ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\LoveGraphics.o" "..\\src\\LoveGraphics.cpp"
..\src\LoveGraphics.cpp: In function 'int main()':
..\src\LoveGraphics.cpp:19:33: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
initgraph(&gdriver,&gmode, "");
^
g++ -o My_CPP_World.exe "src\\LoveGraphics.o"
src\LoveGraphics.o: In function `main':
D:\Eclipse_Photon\Eclipse_CPP\eclipse\MyCCPPWorkSpace\My_CPP_World\Debug/../src/LoveGraphics.cpp:19: undefined reference to `initgraph'
D:\Eclipse_Photon\Eclipse_CPP\eclipse\MyCCPPWorkSpace\My_CPP_World\Debug/../src/LoveGraphics.cpp:20: undefined reference to `setbkcolor'
D:\Eclipse_Photon\Eclipse_CPP\eclipse\MyCCPPWorkSpace\My_CPP_World\Debug/../src/LoveGraphics.cpp:21: undefined reference to `setcolor'
D:\Eclipse_Photon\Eclipse_CPP\eclipse\MyCCPPWorkSpace\My_CPP_World\Debug/../src/LoveGraphics.cpp:22: undefined reference to `cleardevice'
D:\Eclipse_Photon\Eclipse_CPP\eclipse\MyCCPPWorkSpace\My_CPP_World\Debug/../src/LoveGraphics.cpp:23: undefined reference to `circle'
D:\Eclipse_Photon\Eclipse_CPP\eclipse\MyCCPPWorkSpace\My_CPP_World\Debug/../src/LoveGraphics.cpp:25: undefined reference to `closegraph'
collect2.exe: error: ld returned 1 exit status

12:53:51 Build Failed. 6 errors, 1 warnings. (took 1s.578ms)
Re: Undefined Reference To 'initgraph' [message #1806604 is a reply to message #1806592] Sat, 11 May 2019 13:11 Go to previous messageGo to next message
Joost Kraaijeveld is currently offline Joost KraaijeveldFriend
Messages: 273
Registered: July 2009
Senior Member
And your question is?

Cheers,

Joost
Re: Undefined Reference To 'initgraph' [message #1806613 is a reply to message #1806604] Sat, 11 May 2019 22:47 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
:) As Joost pointed out, you didn't ask anything.
But I'm guessing you meant to add "why am I getting these errors?"

Undefined reference to 'sym' is a link error saying you never defined the symbol 'sym'
Which means none of the object files you gave to the linker contain it.
In your case, they are likely in some library and you have to inform the linker which one it is.

You do this by adding -lxxx where the library name is libxxx.<some OS dependent lib extension>
And you add the path containing it to the library search list with -Lpath

To do this with a CDT Managed Build (where Eclipse/CDT creates the makefile),
Project --> Properties --> C/C++ Build --> Settings --> Tool Settings tab --> Linker --> Libraries
The top pane in the resulting dialog is for library names without the -l
And the bottom one is for adding a path to the library search list (without the -L)
Eclipse will add the -l and -L as appropriate.

Previous Topic:project builders order
Next Topic:debugging issues in ARM9 processor
Goto Forum:
  


Current Time: Thu Sep 19 15:11:11 GMT 2024

Powered by FUDForum. Page generated in 0.03608 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top