Error due to #include<graphics.h>
Solution 1
graphics.h
is a non-standard header. Most likely it refers to the old BGI graphics library of the Turbo C DOS compiler. It will only work on that particular compiler. And of course DOS is a completely obsolete OS nowadays.
If you are interested in 3D graphics programming, then OpenGL and/or DirectX are indeed better, modern alternatives, supported by many compilers.
Solution 2
If you try to compile the source code with including “graphics.h” in code::blocks IDE you have to setup winBGIm
library.
- Download
WinBGIm
from http://winbgim.codecutter.org/ or use (direct link) - Extract it.
- Open
graphics.h
, go to line302
changeint right=0
toint top=0
- Copy
graphics.h
andwinbgim.h
files in include folder of your compiler directory. - Copy
libbgi.a
to lib folder of your compiler directory - In code::blocks open
Settings
>>Compiler and debugger
>>linker settings
- Click
Add
button in link libraries part, browse and selectlibbgi.a
file - In right part (ie. other linker options) paste commands
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
- Click
Ok
You can also check this video tutorial.
Solution 3
When you're compiling a C source code having graphics.h header file, you'll need to change the file extension to .cpp. Without doing that, you'll get “fatal error: sstream : no such file directory” error.
So, simply change the .c extension to .cpp. Here's a step-by-step procedure to compiling graphics.h source code if you're using Code::Blocks to run the code.
Solution 4
The sstream error occurs only when you are compiling using gcc not g++ , try using g++ or converting the program to c++ , as far as i know ( since i'm new to this language but i've faced this error before ) so goodluck with that
Ayushi Jha
Software Engineer at Intuit, Inc. Programming blog: The Daily Programmer | Personal site: Ayushi Jha Find me at LinkedIn | Twitter I post a question after a lot of research from the web and elsewhere. For this reason, I am most grateful to fellow users who take the time to understand my question and help me out. You will never see a legitimate answer on my questions without an upvote.
Updated on July 09, 2022Comments
-
Ayushi Jha almost 2 years
I am trying to compile a program which includes the
graphics.h
header file for C. I have added thegraphics.h
andwinbgim.h
header files in the include folder and alsolibbgi.a
to lib folder.Just for testing, I made a simple hello world program and included the
graphics.h
header file.But on compiling I got the following error:
In file included from firstc.c:2:0: c:\mingw\bin../lib/gcc/mingw32/4.7.1/../../../../include/graphics.h:30:59: fatal error: sstream: No such file or directory compilation terminated.
I tried to search in other forums as well, where the same question had been asked, but could not get an answer.
Another question, I came across other graphic options for C and C++ like openGL and DirectX. Should I learn these instead of graphics.h?