I want to learn openGL without relying on IDE configuring for me. But Seems that I have problems with correct flags. Before setting up Makefile for me it's easier to test with BAT file. my build.bat
set src=main.c
set output=main.exe
set include=%cd%\include
set lib=%cd%\lib
set compailer=gcc
set compFlags=-Wall
set linkFlags=-lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32
%compailer% %src% -o %output% %compFlags% -I %include% -L %lib% %linkFlags%
main.c has the same GLFW example code. In the project folder headers are in /include/GLFW
and static lib in /lib
with libglfw3.a
.
when compiling I have long list of errors
D:\Dev\C\OpenGL>gcc main.c -o main.exe -Wall -I D:\Dev\C\OpenGL\include -L D:\Dev\C\OpenGL\lib -lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32
C:\Users\User\AppData\Local\Temp\cc2z12t2.o:main.c:(.text+0x7f): undefined reference to `_imp__glClear@4'
D:\Dev\C\OpenGL\lib/libglfw3.a(init.c.obj):init.c:(.text+0xb9): undefined reference to `__mingw_free'
D:\Dev\C\OpenGL\lib/libglfw3.a(init.c.obj):init.c:(.text+0xda): undefined reference to `__mingw_free'
...
D:\Dev\C\OpenGL\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x2383): undefined reference to `__mingw_free'
D:\Dev\C\OpenGL\lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x4c0c): more undefined references to `__mingw_free' follow
collect2.exe: error: ld returned 1 exit status
I tried to follow the GLFW build guide .
Add -lmingw32
to your link flags. That should deal with __mingw_free
at least I think.
Also -glut32 -glu32
perhaps.
According to the link you posted -lgdi32 -luser32 -lkernel32
are default libraries and need not be specified - should be harmless though.
I was having a very similar problem trying to do the exact same thing (My only difference was no undefined reference to _imp__glClear@4
, that only appeared when not using -lopengl32
). I have fixed all the undefined reference to __mingw_free
and __mingw_realloc
by switching the glfw3 flag from -lglfw3
to -lglfw3dll
. I am still learning so I don't know the real reason why this has fixed the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.