I have recently started learning graphics in C++.
I tried #include <graphics.h>
in my program in codeblocks but it shows error. Then I downloaded graphics.h
header from a site and pasted in the include folder in codeblocks, yet it shows graphics.h:No such file or directory
.
Can anyone teach me how to use graphics.h
in codeblocks?
This is because graphics. h runs is not available in the library folder of CodeBlocks. To successfully compile graphics code on CodeBlocks, setup winBGIm library.
To solve it, open graphics. h file (pasted in include folder in step 3) with Notepad++. Go to line number 302, and replace that line with this line : int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX, Step 10: Save the file.
include
folder where you have installed
Codeblocks. int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
in that line.graphics.h
and winbgim.h
files in include folder of your compiler directorylibbgi.a
to lib folder of your compiler directorylibbgi.a
file-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
For detail information follow this link.
You don't only need the header file, you need the library that goes with it. Anyway, the include
folder is not automatically loaded, you must configure your project to do so. Right-click on it : Build options
> Search directories
> Add
. Choose your include
folder, keep the path relative.
Edit For further assistance, please give details about the library you're trying to load (which provides a graphics.h
file.)
If you want to use Codeblocks and Graphics.h,you can use Codeblocks-EP(I used it when I was learning C in college) then you can try
Codeblocks-EP http://codeblocks.codecutter.org/
In Codeblocks-EP , [File]->[New]->[Project]->[WinBGIm Project]
It has templates for WinBGIm projects installed and all the necessary libraries pre-installed.
OR try this https://stackoverflow.com/a/20321173/5227589
AFAIK, in the epic DOS era there is a header file named graphics.h shipped with Borland Turbo C++ suite. If it is true, then you are out of luck because we're now in Windows era.
It is a tradition to use Turbo C for graphic in C/C++. But it’s also a pain in the neck. We are using Code::Blocks IDE, which will ease out our work.
Steps to run graphics code in CodeBlocks:
To test the setting copy paste run following code:
#include <graphics.h>
int main( )
{
initwindow(400, 300, "First Sample");
circle(100, 50, 40);
while (!kbhit( ))
{
delay(200);
}
return 0;
}
Here is a complete setup instruction for Code::Blocks
How to include graphics.h in CodeBlocks?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With