Undefined Reference To 'initgraph' [message #1806592] |
Sat, 11 May 2019 03:42  |
Eclipse User |
|
|
|
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 #1806613 is a reply to message #1806604] |
Sat, 11 May 2019 18:47  |
Eclipse User |
|
|
|
:) 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.
|
|
|
Powered by
FUDForum. Page generated in 0.09453 seconds