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:
#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 :(
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 (https://wiki.codeblocks.org/index.php/FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F).
heres the print:
https://imgur.com/07SJvb7
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:
libbgi.a
libgdi32.a
..
The full rebuild log is far better than an image, post it (in code tags) if you have more problems.
because the 'libbgi.a' is for the 'graphics.h'.
on past i put it to work... but now i can't :(
I used it with TurboC 30 years ago, but IIRC it was abandoned.
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
https://cboard.cprogramming.com/cplusplus-programming/181839-how-use-graphics-h-codeblocks.html (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.
i know that link but what i found was testing and shooting on dark :(
Quote from: cambalinho on November 11, 2023, 01:44:28 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.
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)
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.
Quote from: cambalinho on November 11, 2023, 01:44:28 AM
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.
You can use this to build WinBGI:
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:
mingw32-make
We also do not forget about .PHONY (https://stackoverflow.com/questions/2145590/what-is-the-purpose-of-phony-in-a-makefile)
.PHONY: clean dirmake rebuild