Generally you don’t need to install compiler separately in CodeBlocks since it also comes with compiler already included. But the problem is newer version of CodeBlock have problem if we try to add Borland Graphics Interface (WinBGIm) support, which allows to run graphics in C++ program. So here is how you can make include<graphics.h> work again in your CodeBlocks.
- Download CodeBlocks (codeblocks-20.03-setup.exe) without MinGW’s GNU GCC compiler, a separate TDM-GCC compiler and WinBGIm binaries from the download section below.
- If you had already installed CodeBlocks (codeblocks-20.03mingw-setup.exe) that comes with compiler then I recommend to uninstall it.
- Install TDM-GCC compiler while installing you need to select MinGW/TDM(32 bit) and make sure add to path option is selected. It makes CodeBlocks auto detect compiler.
- Install CodeBlocks (codeblocks-20.03-setup.exe). When you open CodeBlock it will auto detect compiler. CodeBlocks caches previous compiler settings so to make sure compiler settings are working go to Settings>Compiler then reset defaults. Now it will detect TDM-GCC as default compiler if not detected already.
- Now its time to place downloaded binaries to correct location. Copy the files inside lib (
libbgi.a
) and include (graphics.h
&winbgim.h
) folder to respective folder of TDM-GCC compilerC:\TDM-GCC-32\lib
&C:\TDM-GCC-32\include
. - Now in CodeBlocks inside Settings>Compiler>Linker settings, add
libbgi.a
in Link Libraries: and put-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
in Other linker options: - Save the settings and you are ready to run your graphics program in CodeBlocks.
- Check these images below to make sure you haven’t done any mistake.
In case you want to compile your own binaries
This is completely optional, it only describes how to compile your own binaries but I had provided you pre-compiled binaries. So need to worry about it. I have tried with the binaries and source provided at WinBGIm – Borland BGI Graphics Emulation but it was not working. A working source code of WinBGIm and instruction to compile binaries are available here.
Download section
- WinBGIm Binaries – https://drive.google.com/open?id=1joDbQBIsnjCElEpUx4z59oWbiXcwACha
- CodeBlocks – http://www.codeblocks.org/downloads/26 (remember to download codeblocks-20.03-setup.exe)
- TDM-GCC – https://jmeubank.github.io/tdm-gcc/download/
hi
i could not find your email address so i will ask my question here..
is there a trick or way to get the results of an C program into console..like matlab or python when you are doing numerical stuff you need to save the results..so i want this feature …also i’m using codeblocks…
thank in advance..
You can’t use C program in a console like python. C program must be compiled before running it.
Is there any way that would work for 64-bit programms? This is why I downloaded codeblocks 20.03, for the 64-bit complier. If there is no waty to compile 64-bit executables with graphics.h then I can rollback to 17.12
I think you did’t get this. Here we don’t use compiler that comes with CodeBlock. We download compiler separately and add WinBGIm library there. So There is no problem to use latest CodeBocks. TDM-GCC compiler that use also comes as 64 bit so you can try these binary I provided. If these binary does not work compile your binary from source and it will going to work.
thank you
Perform my mentioned procedure and it generates this error
ld.exe||cannot find -lbgi|
I would appreciate if you can help me
You may have done something wrong please redo. It should work.
Hello I have that error
||error: ld returned 1 exit status|
¿Can you hel me?
Can you please describe how you get this problem, and show full log or the error. Screenshots may be better.