Перейти к содержимому

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

Русские Блоги

Как настроить графическую библиотеку graphics.h в CodeBlocks (наиболее полно и подробно)

вCodeBlocks Компиляция графического кода в среде IDE отобразит ошибку:«Не удается найти graphics.h». Это связано с тем, что в папке библиотеки CodeBlocks не запущен файл graphics.h. Чтобы успешно скомпилировать графический код на CodeBlocks, установитеwinBGImБиблиотека.

Итак, как включить graphics.h в CodeBlocks?

Выполните следующие шаги, чтобы включить «graphics.h» в CodeBlocks для успешной компиляции графического кода в Codeblock.

шаг 1:
Чтобы установить "graphics.h" в CodeBlocks, сначала настройте графическую библиотеку winBGIm. Загрузите WinBGIm с http://winbgim.codecutter.org/ или воспользуйтесь этой ссылкой.
Шаг 2:
Разархивируйте загруженный файл. Будет три файла:

  • graphics.h
  • winbgim.h
  • libbgi.a


Шаг 3:
Скопируйте и вставьте файлы graphics.h и winbgim.h во включаемую папку каталога компилятора. (Если вы установили Code :: Blocks на диск C вашего компьютера, выполните следующие действия: Диск C >> Program Files >> CodeBlocks >> MinGW >> include. Вставьте сюда эти два файла.) Например: C: \ Program Files (x86) \ CodeBlocks \ MinGW \ include


Шаг 4:
Скопируйте и вставьте libbgi.a в папку lib каталога компилятора.

Шаг 5:
Откройте CodeBlocks. Перейдите в Настройки >> Настройки компилятора >> Настройки компоновщика.


Шаг 6:
В этом окне нажмите кнопку «Добавить» в разделе «Библиотека ссылок» и просмотрите.

Выберите файл libbgi.a, скопированный в папку lib на шаге 4.


Шаг 7:
Вставьте команду в правую часть (т.е. другие параметры компоновщика)

-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

Шаг 8:
Нажмите [OK]

Как правило, на этом этапе все проходит успешно, а на последующих этапах может не получиться

Шаг 9:

Попробуйте скомпилировать программу graphics.h на C или C ++, возможно Ошибки все равно будут. Чтобы решить эту проблему, используйте Notepad ++ (или редактор, например Sublime, VSCode), чтобы открыть файл graphics.h (вставьте его в папку include на шаге 3). Перейдите к строке 302 и замените ее следующей строкой: int left = 0, int top = 0, int right = INT_MAX, int bottom = INT_MAX,

Шаг 10:
Сохраните файл. законченный!

нота: Теперь вы можете скомпилировать любую программу C или C ++, которая включает файл заголовка graphics.h. Если вы скомпилируете код C, вы все равно получите сообщение об ошибке: "fatal error: sstream : no such file directory”。

Для этой проблемы, если расширение файла .c, измените его на .cpp.

Name already in use

Setup-Graphics.h-for-Visual-Studio-Code / README.md

  • Go to file T
  • Go to line L
  • Copy path
  • Copy permalink
  • Open with Desktop
  • View raw
  • Copy raw contents Copy raw contents

Copy raw contents

Copy raw contents

How to Setup Graphics.h for Visual Studio Code

Introduction

Hi everyone, Today in this article we will see how to do graphical programming in Visual studio code using the Boreland Graphic interface’s Graphic library.

In case of don’t actually have to use Borland Graphic interface, and you just want to do modern graphic programming you better off using newer library and frameworks that are available.

like DirectX, OpenGL, SDL, SFML, Vulkan etc.

Introduction to graphics.h

The graphics.h header file is a library that provides simple graphics that make it possible to draw lines, rectangles, ellipses, arcs, polygons, images, circle and stars on a graphical window.

To use graphic.h we will have to initialize the graphics drivers on the computer using the initgraph function of graphic.h

STEP-BY-STEP INSTRUCTIONS.

Step 1: Download MinGW

Click on the given link to open MinGW’s website in your browser

image

Now click download.

Step 2: Install MinGW

Now open minGW’s downloaded setup then click on Install and choose your directory where the software should be installed and click on continue.

After installing, you will see an image like below now you have to right click on highlighted (“mingw-32-base”, “mingw32-gcc-g++” and “mysys-base”) box and choose mark for installation.

image

After checking the checkboxes you should see something like the image, now click on Installation on the top left corner and then click on apply changes.

you should see something like shown in the image above.

image

And then click on Apply.

After installation is complete, you should see something like this

image

Then click close to close the installer.

Step 3: Copy MinGW/Bin Path

Now open ‘This PC’ and then open ‘local Disk C’ you will see a folder named minGW open that folder and then open the folder named bin.

image

Now you have to copy the folder path which is on the top of the page in address bar as shown above in the picture.

Then right click and copy or just press ‘Ctrl + C’ on your keyboard.

Step 4: Environment Variables

Now from your start menu open ‘Control Panel’ and click on System. If you don’t find system on your control panel then type ‘environment variable’ on search bar which will show edit system environment in then you have to click on it.

As shown in the picture below

image

Now you have to right click on Advanced System Settings, you should see System Properties then you have click on Environment Variables.

image

Then click on the path in system variable and click on edit as shown in the image above, then click on new and paste the bin path that we have copied in the previous step and then click Ok.

Now click on OK until no pop up remains.

Step 5: Let’s see if MinGW is installed successfully or not

press ‘Win + R’ on your keyboard and now type cmd then press enter then command prompt will open in front of you

image

Now you have to type gcc —version in command prompt and press enter if you see something like the image above, then your minGW setup has been installed successfully.

If you get some error don’t worry just reinstall minGW as shown in the step 2 and step 3 and it should solve the problem.

Step 6: Download Solution-to-graphics.h

To setup «graphics.h» in Visual Studio Code, download the zip file linked above to get all the required files.

extract the downloaded file, there will be three important files:

  • graphics.h
  • winbgim.h
  • libbgi.a

copy graphics.h and winbgim.h files then paste into MinGW/include folder, as shown in the image below.

path might be («C:\MinGW\include»)

image

copy libbgi.a file then paste into MinGW/lib folder, as shown in the image below.

path might be («C:\MinGW\lib»)

image

download zip file from above link and then extract the downloaded file, now you can paste the extracted folder wherever you want and rename the folder name, as shown in the image below.

image

Now open copied folder and right click then choose open with code then your workspace will open in the visual studio code then trust the author to continue, as shown in the image below.

image

Then the folder of your workspace will open in front of you, as shown in the image below.

image

Now let’s talk about src, build and .vscode. How these three folders do works?

  • Src : folder src contains source code files.
  • Build : folder build where compiled .exe file will be stored.
  • .vscode (DO NOT MODIFY ANYTHING IN THIS FOLDER) : .vscode includes c/cpp_properties.json and task.json that are required for compiling your computer graphics source code using graphics library.

Step 8: Download required extensions for visual studio code

Once visual studio code is installed, now we need some extensions so let’s install.

click on the extension button then click on C/C++ extension from Microsoft as shown in the below image. You can search them up if it is not recommended.

then comes the second extension, Named “code runner”. install “code runner” extension by searching it up in visual studio code marketplace, as shown in the image below.

then the last extension comes our “exe runner”, for this, you have to search for “exe runner” in the search box of extensions and then install, as shown in the image below.

image

restart visual studio code after all three extensions have been installed, now we have successfully setup visual studio code for graphics programming.

Step 9: Now go to src folder and click on Hut.cpp and open the file

Step 10: Now build and run the Code

To build from source code using/including graphics library, press “Ctrl+Shift+B” to run the build task you will get the executable file in build folder which will have same name as our source code file but with an extension of “.exe”, as shown in the image below.

image

now you will see the hut.exe file inside the build folder, you have to right click on this then click on run executable, as shown in the image below.

image

Now your program will run and you will see a hut on the console that appears, as shown in the image below.

image

now whenever you need to write a new code, just create a new file in src folder and write your source code in it the and build and run it just like we did for hut.cpp and hut.exe.

CONCLUSION

In the following article, we have seen how can we setup visual studio code for graphical programming using the Boreland Graphic Interface graphic library.

This should be done only in the case that you have to specifically use graphic.h, otherwise you are better off using new library and frameworks like SDL or SFML etc.

So i hope this article was of help to you, Please share it with you friends, collegue and peers.

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.

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

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

Luxury Car Rental in Miami | Reserve a Premium Vehicle with RealCar