4

I have this code:

#include<graphics.h>
int main( )
{
    initwindow( 700 , 700 , "MY First Program");
    circle(200, 200, 150);
    getch();
    return 0;
}

but I get this error:

ld||cannot find -lbgi|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I added it to linker options and also the other things.

What should I do?

genpfault
  • 51,148
  • 11
  • 85
  • 139
ThePHPAddicted
  • 303
  • 1
  • 4
  • 16

4 Answers4

3

Download this and put it in your C compiler's lib folder. Also do not forget to add in the linkers:

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

After doing above, you would get the actual compile error belonging to initgraph() or other.

It is worked for me in Codeblocks 13.12.

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
2

If you are coding in C++11, You must know that <graphics.h> is deprecated in C++11. If you are compiling it in Turbo C++, you must use the initgraph() function and give the path to the BGI folder. For more details, check this out: http://www.programmingsimplified.com/c/graphics.h

shauryachats
  • 9,975
  • 4
  • 35
  • 48
  • QT is a different thing altogether, if you want to use graphics, I recommend OpenGL. A very versatile and easy API for C++, I'm learning it myself too. :) – shauryachats Mar 31 '14 at 17:40
  • 1
    @ShauryaChats are you serious? OpenGL is not easy or straightforward, especially for 2D graphics. Qt may be overkill but at least it has some [friendly 2D APIs](http://qt-project.org/doc/qt-5/qpainter.html) – PeterT Oct 21 '14 at 16:14
  • graphics.h is the front end for the Borland Graphics Interface, a proprietary library shipped with Borland development tools in the late 1980s and early 1990s. It has never been a part of C++ before or after Standardization, and thus could not be deprecated. – user4581301 Feb 18 '22 at 22:24
1

You must include the initgraph() function. Add this:

int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TC\BGI"); //Path where BGI folder appears
matsjoyce
  • 5,744
  • 6
  • 31
  • 38
0

Perhaps your default location of compiler is not under ide folder. In this situation you have to copy graphics.h and winbgim.h in include folder and libbgi in lib folder of default location of the compiler also which may be C:\MinGW\include and C:\MinGW\lib.