Cannot get graphics to work

Hello to everybody!

I'm encountering a problem with any graphics code, even one as simple as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
using namespace 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.

Do you have any suggestions/indications?
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


Tell me how it goes(if you have codeblocks)
I have downloaded Codeblocks and did what you said. Everything works fine now.

Thank you very much for your help.
closed account (3qX21hU5)
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
Topic archived. No new replies allowed.