Graphics h c как подключить

от admin

Adding <graphic.h> for :Graphic Programming Using C/C++ in Ubuntu 20.4

I learn graphic programming long back when I used to be a Windows user (those days and even now students in India start with Windows ) and so C programming I learnt with Turbo C compiler. Over time I moved to Linux (Ubuntu and Fedora) and started using GCC for C and G++ for C++ but did not get any chance to work with graphic programming (I mean those line and circle drawing algorithms from text book).

Recently, one of my previous student ask me how to run graphic programs on Ubuntu (because I pushed them to Ubuntu since very beginning i.e. 1st semester 🙂 , although later things rolled back to Windows after me) . This was new to me also so I decided to looked into it. I asked for his program and found he was trying to run program written for Windows machine (still lots of examples on Internet are for Windows ) on his Ubuntu machine. So, I decided to setup environment on my Ubuntu and test those programs with modification. But it turn out due to change in OS version and modules the setup is not so direct. There are tutorial on the installation and setup but either many of them are outdated or did not worked for. So, I tried to solved all issues and collected the information at one place, this post is based on that collection. So, basically this is collected from various overflow links and Internet tutorial. (My contribution is just make it work on my Ubuntu 20.4 machine for GCC 9.3.0 version). Make sure to check version on your system ($gcc — version)

For graphic programming using C in a Linux OS (Ubuntu ), we need to install <graphics.h> libarary that is not by default in most of C compiler (gcc).

Below are summary of various tips/tricks available on Internet to get the working environment ready.

Many of them are old so can not be apply as it so need little bit change.
Source: https://www.geeksforgeeks.org/add-graphics-h-c-library-gcc-compiler-linux/

This is one of good source for installing graphics.h library but while I was trying with Ubnunt 20.4, it was not working as it is (because of update/change in few dependency) So, Basically one need to install libgraph on Ubuntu to get graphics.h working, “If you want to use graphics.h on Ubuntu platform you need to compile and install libgraph. It is the implementation of turbo c graphics API on Linux using SDL.”

Source of libgraph: http://download.savannah.gnu.org/releases/libgraph/libgraph-1.0.2.tar.gz
One can follow the steps from below link with below suggested changes. For making process easy I have copied steps from there and presented here with required changes.

Step1: First install build-essential by typing
$sudo apt install build-essential

Step 2: Install some additional packages by typing (In this libesd0-dev is is deprecated from Ubuntu 18.04 onwards so running the command directly will break the installation so run below command instead of original command given in the Geeksforgeeks link.)
Error message: Unable to locate package libesd0-dev

$sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0 \
guile-2.0-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev \
libdirectfb-dev libdirectfb-extra libfreetype6-dev \
libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev \
libslang2-dev libasound2 libasound2-dev

Step2.1: Installation of libesd0-dev

Source: https://askubuntu.com/questions/1082722/unable-to-locate-package-libesd0-dev-on-ubuntu-18-04
For this you need to add repositories of xenial, i.e. repository of a previous Ubuntu release which is still supported, in sources.list

Note: nano and gedit are just text editor you can use any text editor of your choice.
Step 2.1.1 : open sources.list with sudo command
$sudo nano /etc/apt/sources.list
or
$sudo gedit /etc/apt/sources.list
Step 2.1.2: past the source of the module in opened file and save. (Below lines are not command but you just have to paste this into the opened file.

Step 2.1.3 Install libesd0-dev
$sudo apt update && sudo apt install libesd0-dev
STEP 3: Now extract the downloaded libgraph-1.0.2.tar.gz file.
STEP 4: Goto extracted folder and run following command (use cd from terminal to goto the unzip file or use open terminal from the open folder.)
Here the running the make after ./configure will give an error about guile-libgraph.c, so you need to configure the path.
Error: guile-libgraph.c:25:10: fatal error: libguile.h: No such file or directory
Source: https://askubuntu.com/questions/942863/trying-to-install-libgraph
4.1 Install or check for guile-2.0-dev installation
$sudo apt install guile-2.0-dev

4.2 configure the path of the module in configuration script.

$CPPFLAGS=”$CPPFLAGS $(pkg-config — cflags-only-I guile-2.0)” \
CFLAGS=”$CFLAGS $(pkg-config — cflags-only-other guile-2.0)” \
LDFLAGS=”$LDFLAGS $(pkg-config — libs guile-2.0)” \
./configure

4.3 Run make command after success of previous command
$make

//if make result success then go to next step else try to debug that first.
4.4 after configuring all the installation requirement now, install the moudle
$sudo make install
4.5 Now copy the source to lib folder
$sudo cp /usr/local/lib/libgraph.* /usr/lib

This will make the environment ready to work with graphics.h file but if you want to run the code, for example below code,you will get error like:
undefined reference to `initgraph’ ubuntu 20.4 and for all called function.
This is due to some path issue so you can get through it just passing some argument (-lgraph) while compiling the source code. Same is applicable for both C/C++. see the next step for compiling and executing the programming.
Note:
1. Many of example code on Internet are for windows based TurboC compiler so that will not run in Linux environment as it.
2. Drop conio.h else you need to install this also for linux , you can use delay() instead of getch() to stop the screen after execution of code.

Example programs: (Note: Not written by but adopted from Internet source, links given at last)

Thank you reading. Hope this will be useful. Let me know if you gets any errors or successfully able to run your program. You can check included links for more details or debug your specific errors.

Name already in use

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

HOW TO SETUP VISUAL STUDIO COMMUNITY FOR GRAPHICAL PROGRAMMING IN C++ using Graphic.h

INTRODUCTION

Hello Everyone, Today we are going to set up Visual Studio Community Edition for Computer Graphical Programming using graphic.h in C++.

WHAT IS «graphic.h»

The graphics.h is a header file in C/C++ that provides access to a simple graphics library that makes it possible to draw lines, rectangles, ovals, arcs, polygons, images, and strings on a graphical window.

WHY YOU SHOULD USE «graphic.h»

In India, In The field of computer science, most of the degrees has at least Computer Graphical Programming course, be it B.Tech, BCA, BSc Cs, or any other degree in Computer science department.

So, if you are taking one of the courses listed above, it is mandatory to use graphic.h for Computer Graphical Programming.

WHY YOU SHOULDN’T USE «graphic.h»

graphics.h is for dos based graphics with max support of 640×480 resolution based on graphics driver and mode selection.

Because, “graphics.h” is really old library and not used anymore.

graphics.h is a 35 years old header that used to exist in Borland version of Turbo C. It is simply outdated & unsupported.

I would also suggest not to use Bloodshed Dev-C++ as it is also a quite outdated.

NOTE: If you are not taking any course that «Strictly» requires you to use graphic.h for Computer Graphical Programming, and just want to learn graphic programming in general or as a hobby we highly recommend that you use one of the many libraries out there which are better (but complicated) than graphics.h. Some of them are:

  1. OpenGL using GLFW (modern openGL)(Recommended)

OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) that use graphic hardware(GPU or Video card) for rendering 2D and 3D vector graphics.

  1. DirectX(Recommended)

DirectX is an application program interface (API) that use graphic hardware(GPU or Video card) for creating and managing graphic and multimedia effects in applications such as games or Dynamic Web pages that will run in MS’s Windows operating systems.

Читать:
Как удалить intellij idea

Latest DirectX 12 is included in Windows 10, 11

  1. SFML

Simple and Fast Multimedia Library (SFML) is a cross-platform software development library that use graphic hardware(GPU or Video card) it is designed to provide a simple application programming interface (API) to various multimedia components in Modern computers.

  1. SDL

SDL (Specification and Description Language) is a program design and implementation language that that use graphic hardware(GPU or Video card) for rendering 2D and 3D graphics. that is used to build actual-time event-driven systems that involve parallel processing

Note: you can setup graphic.h to work with both Visual studio Community/Professional and Visual Studio Code

STEP-BY-STEP INSTRUCTIONS

Step 1: First of all, for using «graphics.h» in the visual studio community, you should have Visual Studio Community installed in your computer. You can download its official version from Microsoft’s Visual studio website CLICK HERE

Step 2: Install Visual Studio Community as you would install any other setup. After installing Visual Studio Community, open Visual studio community installer by searching it in the start menu as shown in below screenshots

Step 3: Once Visual Studio Community Installer opens up click on modify to modify your installation.

Step 4: Choose The Highlighted workload below to download and install it in your Visual Studio Community Installation.

Step 5: After installing the workload, We would also need to download one more file that is WinBGIm Graphics Library for Visual Studio. Here BGI Stands for (Borland Graphics Interface) Click Here, download the “BGI2010.zip” File

Step 6: After downloading, right-click the file and select «Extract All» to unarchive the files in your desired path/directory.

The new directory will be created, named BGI, it has all necessary files that you will need (including the WinBGIm which contains graphic.h, winbgim.h and winbgi.h Libraries and a pre-set project that is already set up to you to test them) in order to create a computer graphics programs in Visual Studio community.

You should now rename of this folder to a name for your own liking that is easy to remember for you, such as “Graphical Programming Workspace”. And copy it to a easily accessible location such as your Document folder or your desktop.

Navigate to that directory. And you will see a bunch of files there which also include Graphics Library files and a sample project.

Step 7: In this folder, open the file named “bgi.vcxproj”. and the project will open in Visual Studio Community.

Step 8: As the Project opens you will see a prompt that asks you to retarget the Project to target the Latest Version of Visual Studio Community.

In this pop-up window choose the latest Windows SDK and Microsoft Platform Toolset version and click on the Ok Button as shown in below Screenshot.

And Visual Studio Community will Reconfigure the Project to target the Current Version of Visual studio community, Windows SDK and Platform Toolset version.

Step 9: In Visual Studio Community, Open** the solution explorer then open the source file and you will see a bunch of files there here create a new source code file(.cpp)

Step 10: Select C++ File (.cpp) File. Give the new file a name(we will use “Test”), and it will be added to your project.

Step 11: Now write this code in test.cpp and Save the file.

Step 12: Now build and run the Code by Clicking on Debug the click on Start without Debugger in drop down menu.

And you will see that your Program runs and a Circle is drawn on the console that opens up as shown in the screenshot.

Now, whenever you would need to write a new code just create a new file and write code in it and run just as we did for test.cpp

CONCLUSION

In this article we have learned How we can use graphic.h in Visual Studio Community which is a part of the Borland Graphics Interface.

This article is especially useful for College students who are taking a Computer Graphics Course.

I hope this article helped you, if you liked it please star this repo and share it with your friends.

About

Today we are going to set up Visual Studio Community Edition for Computer Graphical Programming using graphic.h in C++.

Graphics h c как подключить

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”.

How to use graphics.h in codeblocks?

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?

genpfault's user avatar

6 Answers 6

  1. First download WinBGIm from http://winbgim.codecutter.org/ Extract it.
  2. Copy graphics.h and winbgim.h files in include folder of your compiler directory
  3. Copy libbgi.a to lib folder of your compiler directory
  4. In code::blocks open Settings >> Compiler and debugger >>linker settings click Add button in link libraries part and browse and select libbgi.a file
  5. In right part (i.e. other linker options) paste commands -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  6. Click OK

For detail information follow this link.

Dinesh Subedi's user avatar

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.)

John WH Smith's user avatar

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

In Codeblocks-EP , [File]->[New]->[Project]->[WinBGIm Project]

Codeblocks-EP WinBGIm Project Graphics.h

It has templates for WinBGIm projects installed and all the necessary libraries pre-installed.

Похожие статьи