简体   繁体   English

static 的带有 GCC Mingw 标志的 GLFW 无法按文档说明工作

[英]GLFW with GCC Mingw flags for static doesn't work as documented

I want to learn openGL without relying on IDE configuring for me.我想在不依赖 IDE 为我配置的情况下学习 openGL。 But Seems that I have problems with correct flags.但似乎我对正确的标志有问题。 Before setting up Makefile for me it's easier to test with BAT file.在为我设置 Makefile 之前,使用 BAT 文件进行测试更容易。 my build.bat我的 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. main.c 具有相同的 GLFW 示例代码。 In the project folder headers are in /include/GLFW and static lib in /lib with libglfw3.a .在项目文件夹中,标题位于/include/GLFW/lib中的 static lib 和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 .我尝试遵循 GLFW 构建指南

Add -lmingw32 to your link flags.-lmingw32添加到您的链接标志中。 That should deal with __mingw_free at least I think.至少我认为这应该处理__mingw_free

Also -glut32 -glu32 perhaps.还有-glut32 -glu32也许。

According to the link you posted -lgdi32 -luser32 -lkernel32 are default libraries and need not be specified - should be harmless though.根据您发布的链接-lgdi32 -luser32 -lkernel32是默认库,不需要指定 - 不过应该是无害的。

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 ).我在尝试做完全相同的事情时遇到了一个非常相似的问题(我唯一的区别是没有undefined reference to _imp__glClear@4 ,只有在不使用-lopengl32时才会出现)。 I have fixed all the undefined reference to __mingw_free and __mingw_realloc by switching the glfw3 flag from -lglfw3 to -lglfw3dll .我通过将 glfw3 标志从-lglfw3切换到-lglfw3dll修复了对__mingw_free__mingw_realloc的所有未定义引用。 I am still learning so I don't know the real reason why this has fixed the problem.我仍在学习,所以我不知道解决问题的真正原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM