Author Topic: how use Graphics.h?  (Read 2685 times)

Offline cambalinho

  • Multiple posting newcomer
  • *
  • Posts: 93
how use Graphics.h?
« on: November 10, 2023, 08:42:07 pm »
i use CodeBlocks with mingw compiler.
for use 'Graphics.h', i must add the 'libbgi.a' library.
but i continue with some compiler\linker error: "ld.exe||cannot find -lbgi|".
yes i add the linker options:
"-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32"
heres my testing code:
Code
#include <iostream>
#include <graphics.h>
#include <conio.h>

using namespace std;

int main()
{
    int gdriver = DETECT, gmode;
    int x1 = 200, y1 = 200;
    int x2 = 300, y2 = 300;
    //clrscr();

    initgraph(&gdriver, &gmode,  NULL);
    line(x1, y1, x2, y2);
    getch();
    closegraph();
    return 0;
}
(i need find, too, the another 'conio.h' too)
maybe the problem it can the library compatibly :(

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1600
Re: how use Graphics.h?
« Reply #1 on: November 10, 2023, 08:59:17 pm »
Where is libbgi.a? Probably you must add the path to the linker search paths.

Linking problems are best solved if you post a full rebuild log.

Offline cambalinho

  • Multiple posting newcomer
  • *
  • Posts: 93
Re: how use Graphics.h?
« Reply #2 on: November 10, 2023, 09:03:57 pm »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1600
Re: how use Graphics.h?
« Reply #3 on: November 10, 2023, 09:13:11 pm »
Does libbgi.a exist in the lib folder?.

You are adding libbgi.a twice. All the "Other linker options" content should be moved to the left with no paths:
Code
libbgi.a
libgdi32.a
..
The full rebuild log is far better than an image, post it (in code tags) if you have more problems.

Offline cambalinho

  • Multiple posting newcomer
  • *
  • Posts: 93
Re: how use Graphics.h?
« Reply #4 on: November 10, 2023, 09:22:00 pm »
because the 'libbgi.a' is for the 'graphics.h'.
on past i put it to work... but now i can't :(

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1600
Re: how use Graphics.h?
« Reply #5 on: November 10, 2023, 10:05:48 pm »
I used it with TurboC 30 years ago, but IIRC it was abandoned.


Offline cambalinho

  • Multiple posting newcomer
  • *
  • Posts: 93
Re: how use Graphics.h?
« Reply #6 on: November 11, 2023, 01:34:24 am »
after several time, i found the problems:
1 - the library and the headers files are for Code Blocks 32 bits and not 64 bits;
2 - the files are for "CodeBlocks\MinGW\i686-w64-mingw32\..." and not "CodeBlocks\MinGW\..." folder!!!
the rest is the same(add the library on project and the linker options).
thanks for all to all

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7626
    • My Best Post
Re: how use Graphics.h?
« Reply #7 on: November 11, 2023, 01:35:23 am »
https://cboard.cprogramming.com/cplusplus-programming/181839-how-use-graphics-h-codeblocks.html

Another website with the same question; if the OP wants help, from me, they need to post a build log and post information about the compiler they are using.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cambalinho

  • Multiple posting newcomer
  • *
  • Posts: 93
Re: how use Graphics.h?
« Reply #8 on: November 11, 2023, 01:44:28 am »
i know that link but what i found was testing and shooting on dark :(

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7626
    • My Best Post
Re: how use Graphics.h?
« Reply #9 on: November 11, 2023, 01:50:37 am »
i know that link but what i found was testing and shooting on dark :(

Next time post the build log or I will put you on ignore!
The build log would have given the error that you were mixing 64 and 32 bits object and we could have help you.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cambalinho

  • Multiple posting newcomer
  • *
  • Posts: 93
Re: how use Graphics.h?
« Reply #10 on: November 11, 2023, 01:30:06 pm »
i'm sorry, but  do you mean the 'build log' tab page list?
"
-------------- Clean: Debug in testgraphics (compiler: GNU GCC Compiler)---------------

Cleaned "testgraphics - Debug"

-------------- Build: Debug in testgraphics (compiler: GNU GCC Compiler)---------------

x86_64-w64-mingw32-g++.exe -Wall -g -std=gnu++98 -m32  -c C:\Users\Utilizador\Documents\CodeBlocks\testgraphics\Untitled1.cpp -o obj\Debug\Untitled1.o
x86_64-w64-mingw32-g++.exe  -o bin\Debug\testgraphics.exe obj\Debug\Untitled1.o  -m32 -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32  "C:\Program Files (x86)\CodeBlocks\MinGW\i686-w64-mingw32\lib\libbgi.a"
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libgdi32.a when searching for -lgdi32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib\libgdi32.a when searching for -lgdi32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libgdi32.a when searching for -lgdi32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgdi32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libcomdlg32.a when searching for -lcomdlg32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib\libcomdlg32.a when searching for -lcomdlg32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libcomdlg32.a when searching for -lcomdlg32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcomdlg32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libuuid.a when searching for -luuid
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib\libuuid.a when searching for -luuid
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libuuid.a when searching for -luuid
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -luuid
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/liboleaut32.a when searching for -loleaut32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib\liboleaut32.a when searching for -loleaut32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/liboleaut32.a when searching for -loleaut32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -loleaut32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libole32.a when searching for -lole32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib\libole32.a when searching for -lole32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libole32.a when searching for -lole32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lole32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libstdc++.dll.a when searching for -lstdc++
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libstdc++.a when searching for -lstdc++
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0\libstdc++.a when searching for -lstdc++
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libstdc++.dll.a when searching for -lstdc++
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libstdc++.a when searching for -lstdc++
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lstdc++
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libmingw32.a when searching for -lmingw32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib\libmingw32.a when searching for -lmingw32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libmingw32.a when searching for -lmingw32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmingw32
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libgcc_s.a when searching for -lgcc_s
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib\libgcc_s.a when searching for -lgcc_s
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/libgcc_s.a when searching for -lgcc_s
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc_s
//.......................................
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 2 second(s))
25 error(s), 0 warning(s) (0 minute(s), 2 second(s))"
(i'm testing the Code Blocks 64 bits for understand if these is what you was asking for.. nothing more)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7626
    • My Best Post
Re: how use Graphics.h?
« Reply #11 on: November 11, 2023, 01:43:38 pm »
Code
x86_64-w64-mingw32-g++.exe -Wall -g -std=gnu++98 -m32

Using -m32 or -m64 almost always result in errors because most MinGW GCC toolchains do not have both sets of libraries.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Online nenin

  • Almost regular
  • **
  • Posts: 227
Re: how use Graphics.h?
« Reply #12 on: November 15, 2023, 09:29:37 pm »
i know that link but what i found was testing and shooting on dark :(
If you trying to study C/C++ examples with BGI / Graphics.h are very wrong way to do it. BGI is very old DOS library somehow ported to Win 20 years ago probably with purpose to compile some very old code. 
Here you can find sources  https://github.com/nirin/WinBGI . If you will be lucky enough you can impost VS project and build library for your version of the MinGW. It will be interesting experience, taking in account that gcc is contemporary compiler and 20 y.o. code might not pass requirements of the current  C/C++ standards.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1600
Re: how use Graphics.h?
« Reply #13 on: November 16, 2023, 01:09:16 pm »
You can use this to build WinBGI:
Code
CC = g++
OUT_FILE_NAME = winbgi.a
CFLAGS = -fPIC -O0 -g -Wall -c -fpermissive
INC =
OBJ_DIR = obj
OUT_DIR = lib

# Enumerating of every *.cpp as *.o and using that as dependency
$(OUT_FILE_NAME): $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(wildcard *.cpp))
ar -r -o $(OUT_DIR)/$@ $^

#Compiling every *.cpp to *.o
$(OBJ_DIR)/%.o: %.cpp dirmake
$(CC) -c $(INC) $(CFLAGS) -o $@  $<

dirmake:
@if not exist $(OUT_DIR) mkdir $(OUT_DIR)
@if not exist $(OBJ_DIR) mkdir $(OBJ_DIR)

clean:
@if exist $(OBJ_DIR) rmdir /S /Q $(OBJ_DIR)
@if exist $(OUT_DIR)\$(OUT_FILE_NAME) del $(OUT_DIR)\$(OUT_FILE_NAME)
@if exist Makefile.bak del Makefile.bak

rebuild: clean build
Create a file named Makefile in the WinBGI folder, paste the code above, open a console in the WinBGI folder and execute:
Code
mingw32-make

Offline omlk

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: how use Graphics.h?
« Reply #14 on: November 16, 2023, 02:25:10 pm »
We also do not forget about .PHONY

Code
.PHONY: clean dirmake rebuild