Graphics h c как подключить
Перейти к содержимому

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

  • автор:

Как подключить graphics.h

"graphics.h", как правильно подключить?
Подскажитє пожалуста, как подключить библиотеку graphics.h к с++. Сколько пробовал никак не.

Не могу подключить файлы из BGI для <graphics.h>
На этапе линка, компилятор (Borland C++ 6.0) выдает ошибку: Fatal: expected a ‘:’ or ‘=’: bgi .

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.

frogatto's user avatar

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.

How to Add Graphics in Dev C++

If you’re new to graphics and trying to learn the basics, practicing is a good idea. If you prefer using the Dev C++ IDE, you’ll need to use the graphics.h header file to enable the compiler to handle graphics-related operations.

Adding the graphics.h library to Dev C++ is a simple process. If you’re having trouble getting the graphics header file into your Dev C++ compiler, this tutorial can guide you through the step-by-step procedure to add graphics in Dev C++.

Additionally, you can look into other modern libraries that are similar and better than graphics.h. To name a few –

  • OpenGL
  • DirectX
  • SDL
  • SFML
  • Allegro

How to add graphics in dev C++ (follow these steps)

Step 1: Download/update the latest version of dev C++

Having the latest version of the dev c++ will ensure you have the latest features and avoid application bugs and security patches. It also ensures you face no issues while integrating the graphics with the compiler.

You can download the latest build of dev C++ which is obviously an open-source IDE. For this tutorial, I’m using the 5.11 version. You might get an upgrade, but the procedure should remain the same. To check your dev c++ version, select “help” from the top menu and go to the “About Dev C++” section.

dev-c-version

Step 2: Add header source files into the Dev C++ directory

Next, you need to download graphics library files and add them to the appropriate folders under the MinGW64 directory. Follow this –

  1. First, download the header files from this Google drive link and extract the files.
  2. It contains three files – graphics.h, winbgim.h and libbgi.a.
  3. You need to copy “graphics.h” and “winbgim.h” into include the directory of Dev-Cpp program resource files. The exact directory address is –
    • C:\Program Files (x86)\Dev-Cpp\MinGW64\include
  4. Next, copy “libbgi.a” to the lib folder, which should be inside MinGW64. The directory address is –
    • C:\Program Files (x86)\Dev-Cpp\MinGW64\lib

Double-check the include and lib folders have these files to proceed to the next step.

How to add graphics in dev C++

Step 3: Change compiler suit in Dev C++

Compiler suites combine the latest stable release of the GCC toolset and open-source MinGW runtime APIs to build an open-source alternative to Microsoft’s compiler. You can set the TDM – GCC version to the latest stable release, which can be 12.1.0 [as of now].

  1. First, open the Dev C++ application.
  2. On the right side of the toolbar, you will have the drop-down menu to select the desired compiler suit.
  3. Set it to the latest TDM — GCC [version] 32-bit release .

Step 4: Configure required linkers for graphics

Configuring linkers is vital; this program will help link a program’s object modules into a single object file. For graphics.h setup, you will need these linkers to be set for the selected compiler suite, aka the latest TDM — GCC release .

Steps to configure graphics.h linkers:

  1. On Dev, C++, look for the Tool option on the top menu.
  2. Expand tools and select Compiler Options.
  3. You should arrive on the general tab of the compiler options window.
  4. Ensure the “Add the following commands when calling the linker” check box is selected.
  5. Then add these linkers in the input box – (copy and paste this line)
    • -libgcc -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  6. Then click on OK to save.

Compiler-options-linkers-for-graphics.h

When complete, you are ready to use graphics.h header in your c or c++ programs.

Step 5: Verify whether graphics.h header is working (optional)

Create a new source file and write a program to test graphics.h header. You can try it with anything you want; for example, I’m trying to print GANA (in Hindi) using basic graphics output primitives…

And here’s the output:

print-gana-in-hindi-using-graphics-in-c

Still unable to add graphics in Dev C++?

Following these steps should set you up with graphics.h header on Dev C++. If it still doesn’t work, ensure you have followed the process thoroughly… or try to perform a clean installation of the Dev C++.

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

Ajit kumar

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.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *