#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
usingnamespace std;
int main()
{
int gdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"");
errorcode=graphresult();
if(errorcode !=grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
else cout<<"Graphics initialised!\n";
closegraph();
return 0;
}
I have tried to compile it in Mingw, in Devc++, and in an old borland compiler. None of these work. The compilation works fine, but when I try to run the file I get something like this [Linker error] undefined reference to `initgraph' for all grahpic related functions.
I suspect it is a linking problem but I cannot figure how to get over it. I have tried writing -L"C:/Dev-Cpp/lib" in the linker command line, but didn't work.
Well, if you were to use codeblocks i would add the lib like so:
1. right click the project name
2. Hit "build options"
3. Select the "linker settings" tab
4. Under "link libraries" hit add
5. Find your lib file and add it
6. Hit yes to keep it as a relative path
If you were working on visual studios you could have linked the libraries the same way almost by going to project settings-> linker -> then add in the path to search for libraries at -> then input and add in the library file like d3d9.lib