- Forum
- General Programming Boards
- C Programming
- problem to use graphics.h with gcc in windows??
-
01-13-2012
#1
Registered User
problem to use graphics.h with gcc in windows??
these are the header files for my project
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#include<process.h>
#include<graphics.h>
but when i compile it with gcc in windows 7 it gives error!!fatal error:graphics.h:No such file or directory compilation terminated.
how to compile this program..i know the graphics.h is for turbo compiler..How to use it under gcc??
-
01-13-2012
#2
and the hat of int overfl
Isn’t it time you left the past behind?
Even assuming for the moment you could just «get» a header file, that still won’t fix the 16-bit issues, low graphic resolution and a host of other problems within the code you’re trying to port.
At some point, the only sensible thing is to just write it again, taking FULL advantage of everything your modern platform has to offer.
-
01-13-2012
#3
Novice
Originally Posted by nowshek
these are the header files for my project
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#include<process.h>
#include<graphics.h>
but when i compile it with gcc in windows 7 it gives error!!fatal error:graphics.h:No such file or directory compilation terminated.
how to compile this program..i know the graphics.h is for turbo compiler..How to use it under gcc??Do you even have an idea why you need any of those headers?
Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.
-
01-14-2012
#4
Registered User
There is no such thing as a global graphics header that you can just include in your code and hey presto write things like ‘drawBox(x, y, RED);’
Modern architecture and systems have rendered anything like that completely obselete. The only way your graphics header (from turbo c) is going to work in the very near future is via an emulated environment that runs in your OS , right now you wil be lucky if it runs, you just cannot access the screen like that anymore, and its rubbish and an anachronism anyway, for archaeoligists only.
What you have to do these days is to learn to use an intermediate library that wil give you graphics commands (and related media controls) you can use in a modern context. My first foray into this was SDL, ‘simple direct media layer’ ie it provides that layer interface you need now to output graphics. its a bit like learning a mini language on top of the parent one, so get busy!Thought for the day:
«Are you sure your sanity chip is fully screwed in sir?» (Kryten)
FLTK: «The most fun you can have with your clothes on.»
Stroustrup:
«If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little ‘C++ Inside’ sticker on it'»
Popular pages
- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish
Recent additions
- How to create a shared library on Linux with GCC — December 30, 2011
- Enum classes and nullptr in C++11 — November 27, 2011
- Learn about The Hash Table — November 20, 2011
- Rvalue References and Move Semantics in C++11 — November 13, 2011
- C and C++ for Java Programmers — November 5, 2011
- A Gentle Introduction to C++ IO Streams — October 10, 2011
Similar Threads
-
Replies: 1
Last Post: 11-09-2011, 06:06 AM
-
Replies: 1
Last Post: 11-03-2009, 01:17 PM
-
Replies: 1
Last Post: 02-23-2005, 01:26 PM
-
Replies: 1
Last Post: 07-29-2003, 05:32 PM
-
Replies: 3
Last Post: 01-16-2002, 05:25 PM
Когда я делаю:
#include <graphics.h>
Это говорит:
фатальная ошибка: graphics.h: нет такого файла или каталога
Как это исправить?
Я использую кодовые блоки 16.01
1
Решение
Использование угловых скобок «<> «предполагает, что graphics.h является частью стандартной библиотеки C. После некоторых исследований выясняется, что этот файл больше не включен в библиотеку. Если вы хотите продолжить использовать эту библиотеку, вам нужно будет найти graphics.h и разместить ее в том же месте, что и ваш исходный код.
В исходном коде вы напишите:
#include "graphics.h"
3
Другие решения
Шаг 1: Загрузите библиотеку graphics.h из http://winbgim.codecutter.org/ или используйте это ссылка на сайт.
Шаг 2: Извлеките загруженный файл. Вы получите три файла:
graphics.h
winbgim.h
libbgi.a
Шаг 3: Скопируйте и вставьте файлы graphics.h и winbgim.h в папку include вашего каталога компилятора. (Если у вас установлен Code :: Blocks на диске C вашего компьютера, пройдите: Disk C >> Program Files >> CodeBlocks >> MinGW >> include, Вставьте туда эти два файла.)
Шаг 4: Скопируйте и вставьте libbgi.a в папку lib вашего каталога компилятора.
Шаг 5: Откройте Code :: Blocks. Идти к Settings >> Compiler >> Linker settings
Шаг 6: В этом окне нажмите кнопку «Добавить» под частью «Связать библиотеки», найдите и выберите файл libbgi.a, скопированный в папку lib на шаге 4.
Шаг 7. Перейдите в «Другие параметры компоновщика» в правой части и вставьте эти команды:
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
Шаг 8: Убедитесь, что вы правильно выполнили шаги 6 и 7! Вот скриншот предыдущих двух шагов. Затем нажмите Ok.
Graphics.h in codeblocks - Compiler Settings
Global Compiler Settings >> Linker Settings
Шаг 9: Если вы сейчас попробуете скомпилировать программный код graphics.h в C или C ++, вы все равно получите ошибку. Чтобы решить эту проблему, откройте файл graphics.h (вставленный в папку include на шаге 3) в текстовом редакторе. Перейдите к строке 302 и замените эту строку этой строкой:
"int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX"
если он правильный (такой же, как указано выше), оставьте его как есть
Сохраните файл. Готово!
Теперь вы можете скомпилировать любую программу на C или C ++, содержащую graphics.h заголовочный файл. Если вы компилируете C-коды, вы все равно получите сообщение об ошибке: “fatal error: sstream : no such file directory”, Для этой проблемы, если ваше расширение файла .с, измените его на .cpp,
1
вставьте graphics.h и winbgim.h в папку C: MinGW include. Затем вставьте libbgi.a в C: MinGW lib. это решение будет работать. потому что место установки вашего компилятора по умолчанию установлено в C: MinGW. в противном случае вы можете изменить место установки вашего компилятора в codebolck.
Настройка >> Настройка глобального компилятора >> Исполняемый файл набора инструментов
1
graphics.h is used for drawing graphics in c language. You can draw the different shapes, graphs, or write your name using this library in c language. This library is pretty cool. But questions come in our mind that how to include graphics.h library in our CodeBlocks software and can start drawing amazing graphics. So let’s move towards the answer on how to include graphics.h in CodeBlocks…
Note: New Codeblocks version(20.03 or later) that comes with the MinGW compiler doesn’t work. If you have already installed codeblocks with the MinGW version then please uninstall it and reinstall the codeblocks setup and MinGW compiler separately. Here are the links for codeblocks and the MinGW.
Codeblocks: http://www.codeblocks.org/downloads/26 (select only setup file, e.g. “codeblocks-20.03-setup.exe”)
MinGW: https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe (After Installation add the path to the Environment variable. The path will be “C:MinGWbin”)
step 1
Download WinBGIm from http://winbgim.codecutter.org/ or use this link.
step 2
Extract the downloaded file. You’ll get three files:
- graphics.h
- winbgim.h
- libbgi.a
step 3
Copy and paste graphics.h and winbgim.h files into the include folder of your compiler directory. (If you have MinGW installed in C drive of your computer, go through Disk C >> MinGW >> include. Paste these two files there.)
step 4
Copy and paste libbgi.a to the lib folder of your compiler directory. (If you have MinGW installed in C drive of your computer, go through Disk C >> MinGW >> lib. Paste these one files there.)
step 5
Open Code::Blocks. Go to Settings >> Compiler >> Linker settings.
step 6
In that window, click the Add button under the “Link libraries” part, and browse and select the libbgi.a file copied to the lib folder in step 4.
step 7
Go to “Other linker options” on the right part and paste these commands:
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
step 8
Make sure you got steps 6 and 7 right! Here’s a screenshot of the previous two steps. Then, click Ok.
step 9
If you now try compiling a graphics.h program code in C or C++, you’ll still get error. 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,
Save the file. Done!
Now you can compile any C or C++ program containing graphics.h header file. If you compile C codes, you’ll still get an error saying: “fatal error: sstream : no such file directory”. For this issue, if your file extension is .c, change it to .cpp.
[If still it is not giving an output then use this link and download ‘libbgi.zip’ file then extract it. you are getting “libbgi.a” file. Copy and paste libbgi.a to the lib folder of your compiler directory.(If you have CodeBlocks installed in C drive of your computer, go through: Disk C >> Program Files >> CodeBlocks >> MinGW >> lib. Paste these one files there.) now your program will work.]
- Remove From My Forums
-
Question
-
fatal error C1083: Cannot open include file: ‘graphics.h’: No such file or directory
Can anyone tell me about this problem step by step ?????
Answers
-
follow33 wrote: fatal error C1083: Cannot open include file: ‘graphics.h’: No such file or directory
As the other responders have pointed out, this means that graphics.h is not found on your computer in any of the places VC++ 2005 Express Edition is configured to look.
To supplement that information, graphics.h is not a header file that is provided with the VC++ standard libraries: It is not part of the ANSI/ISO C/C++ Standard Libraries. It is not provided with the Windows Platform SDK.
You will need to obtain graphics.h and any supporting libraries from whoever provides it. If it is part of the Borland BGI graphics model, what you will need to do is convert from graphics.h to something that works in VC++ on Win32. You might try searching the internet for any port that others have done.
— Dennis
All replies
-
It is simple, in your code you have the line
#include «graphics.h» or #include <graphics.h>
But the file graphics.h can not be found by the compiler.
If you have graphics.h on your computer then you must make sure that the path where it resides is in the include search path.
This is done through tools->options->projects and solutions->vc++ directories and switch show directories for to include files. Add the path to graphics.h there and then recompile. You must also make sure that any library files are also put into the lib path, this is done by switching show directories for to library files and then putting the path to the library files in there.
-
I think in the old DOS days, Borland C++ shipped a graphic library and the header file was ‘graphics.h’. I am just curious — are you compiling old code using this modern compiler?
-
follow33 wrote: fatal error C1083: Cannot open include file: ‘graphics.h’: No such file or directory
As the other responders have pointed out, this means that graphics.h is not found on your computer in any of the places VC++ 2005 Express Edition is configured to look.
To supplement that information, graphics.h is not a header file that is provided with the VC++ standard libraries: It is not part of the ANSI/ISO C/C++ Standard Libraries. It is not provided with the Windows Platform SDK.
You will need to obtain graphics.h and any supporting libraries from whoever provides it. If it is part of the Borland BGI graphics model, what you will need to do is convert from graphics.h to something that works in VC++ on Win32. You might try searching the internet for any port that others have done.
— Dennis
-
I’ve used this Windows replacement version of Borland’s BGI graphics before to get an old DOS program converted to Windows. My memory is a bit vague, remember messing with it a bit to get it bang it into shape. If this is from a book, burn it to make hot dogs.
Semester 7 at college came up with a bunch of new and interesting stuff. One of them is the computer graphics lab, where we all got to do simple graphic programming in C.
Soon enough, this turned out to be a bit uneasy.
The reason was that we were forced to work in Windows, since there is no support for graphics.h in the gcc compiler in Ubuntu. To make things worse, the computers had Windows 7, and we had to install a simulator called DOS-box to run the programs properly. All this felt so messy and I just wanted to run back to the comfort of programming in Ubuntu!
Then there was some solution here. Basically, we’ve to install some packages and libraries which enable us to compile graphics.h programs in linux. The original article is a bit old and many packages mentioned are obsolete now. So I’ve written a patched up, more up-to-date version of the same.
Hope this saves you from going back to the bitter blue screen of Turbo C 
Click image to enlarge
Step #0
Make sure you have the basic compilers installed.
You need the build-essential package. For this, run the command:
sudo apt-get install build-essential
Step #1
First we need to install a hand full of packages. You can simply run the following command and get it all done.
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev libsdl1.2debian-all libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev libslang2-dev libasound2 libasound2-dev
Step #2
Now, download libgraph.
Copy the file libgraph-1.0.2.tar.gz to our home folder. Right click on the file and select Extract here.
Open a terminal and run the following commands, one by one.
cd libgraph-1.0.2
./configure
sudo make
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib
Step #3
Now you’re ready to compile your C program!
You have to type in the line #include<graphics.h> , just like you’d do in Windows.
In programs using graphics.h in Turbo C, you’ll be using something like this:
int gd=DETECT,gm;
initgraph(&gd,&gm,»c:\tc\bgi»);
In Ubuntu, you replace the «c:\tc\bgi» part with a NULL
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
Finally, while compiling the C file, don’t forget to add a -lgraph parameter. The code will be something like this:
gcc heart.c -o heart -lgraph
./heart
And there you go! 
Feel free to use the example code I made: heart.c
Was this post helpful? Let us know:
Bugs:
Although this implementation helps us to run all graphics.h functions, some predefined constants like SOLID_FILL may not be supported. Anyways, we can use integers instead of such names. This fixes the problem without much effort.
The graphics window can occasionally crash on focus. Rather than a bug in the graphics.h implementation, this is a common bug in gnu/linux graphics which apparently affects many other applications.

MUST READ – Sorry for not updating this post for the long time. Many users are complaining that is is not working with newer version of CodeBlocks. So there is another way to run Borland Graphics Interface. Since WinBGIm is very old maybe it is not working with new linker or whatever. So to make this work you need to install GCC compiler separately and place binaries there. Here is how to do that – https://sangams.com.np/adding-graphics-h-tdm-gcc-c-compiler/
Code::Blocks is mostly used opensource IDE due its great features. However it can’t run graphics programs unless you include graphics.h. But we can make it work by adding WinBGIm graphics library manually. That way we can use #include<graphics.h> in Code::Blocls.
Code::Blocks is lightweight and easy to use and becoming opensource it is available for Windows, Linux and Mac and is free to download and use. It is best IDE for beginners who wants to learn and C, C++ and FORTRAN or for creating small projects. With addition of WinBGIm in Code::Blocks we can use graphics.h header file then compile and run graphics program in C++ without any errors. Let’s see how to include graphics.h in Code::Blocks.
How to add graphics.h support in Code::Blocks?
- Download WinBGIm from the download section below. Downloading from other website may not work since official graphics.h has minor error.
- Extract it.
- Open info.txt for linker options and more information.
- Copying MinGW folder to your Code::Blocks installation directory. Default Code::Blocks installation directory is
C:Program Files (x86)CodeBlocks. There will be MinGW folder already. Copying new MinGW folder only adds some library (libbgi.a) and header (winbgim.h,graphics.h) files in that directory. To manually add files, copygraphics.handwinbgim.hfiles in include folder of your compiler directory which isC:Program Files (x86)CodeBlocksMInGW. And copylibbgi.ato lib folder of your compiler directory. - Open Code::Blocks. In open Settings >> Compiler >>Linker Settings. Click Add button in link libraries part and browse and select
libbgi.afile you just copied to MinGW folder. - In right part (i.e. other linker options) paste commands
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 - Click OK.
If you didn’t see MinGW folder then it might be installed in different location. Check in C:MinGW.
You can also watch my short video about adding graphics.h support in Code::Blocks
Now you can run graphics program in Code::Blocks by including graphics.h header. I have added a sample program clock.cpp with that WinBGIm archive file, you can try compiling it.
Note: If you are getting sstream not found error, then you probably trying to run a .c file program. sstream is c++ header so graphics.h won’t works with c.
You may also like How To Install Dark Themes In CodeBlocks?
Download WinBGIm graphics.h library
You can download corrected graphics library files from here – https://drive.google.com/open?id=1joDbQBIsnjCElEpUx4z59oWbiXcwACha
Here is the official link for WinBGIm graphics library – http://www.codecutter.net/tools/winbgim/ but it has small problem with graphics.h file which is have corrected. Line 302 has been replaced by int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,.
To setup OpenGL and GLUT in Code::Blocks there is a good video available in YouTube – How to setup OpenGL and GLUT with CodeBlocks on Windows.
Compiling graphics codes on CodeBlocks IDE shows an error: “Cannot find graphics.h”. 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.
How to include graphics.h in CodeBlocks ?
Please follow below steps in sequence to include “graphics.h” in CodeBlocks to successfully compile graphics code on Codeblocks.
Step 1 : To setup “graphics.h” in CodeBlocks, first set up winBGIm graphics library. Download WinBGIm from http://winbgim.codecutter.org/ or use this link.
UPDATE: The build of the library at http://winbgim.codecutter.org/ is old and was last built around 2006. While linking against that using 64 bit compiler toolchain it results into linking error. Here at https://github.com/ki9gpin/WinBGIm-64 is a recent build of the library bringing 64 bit compatibility. Some win32 system calls have also been updated to MSDN recommended 64 bit alternates for preciseness.
Step 2 : Extract the downloaded file. There will be three files:
- graphics.h
- winbgim.h
- libbgi.a
Step 3 : Copy and paste graphics.h and winbgim.h files into the include folder of compiler directory. (If you have Code::Blocks installed in C drive of your computer, go through: Disk C >> Program Files >> CodeBlocks >> MinGW >> include. Paste these two files there.)
Step 4 : Copy and paste libbgi.a to the lib folder of compiler directory.
Step 5 : Open Code::Blocks. Go to Settings >> Compiler >> Linker settings.
Step 6 : In that window, click the Add button under the “Link libraries” part, and browse.
Select the libbgi.a file copied to the lib folder in step 4.
Step 7 : In right part (ie. other linker options) paste commands
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
Step 8 : Click Ok
Step 9 : Try compiling a graphics.h program in C or C++, still there will be an error. 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. Done !
Note : Now, you can compile any C or C++ program containing graphics.h header file. If you compile C codes, you’ll still get an error saying: “fatal error: sstream : no such file directory”.

















