MinGW can't find GLFW libraries

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

Hi guys need some help getting MinGW to link GLFW's libraries. I can't find any answers on the web or rather not any that I can understand. I have tried to specify the path to the libs folder using -L and I have added the lib's and include's to MinGW's.

I have even tried changing the names of the libs. The compiler never complains about not finding the headers but the linker says it cant find whatever lib I specify. I have been at GLFW's site but I'm afraid that I don't understand much of what they are trying to tell me. I'm on windows7 using MinGW via the command line since I can't get it to work with Code::Blocks either. I have tried following the installation instructions on opengl-tutorial.org but that sadly starts to complain about something to do with ANT which I don't understand at all. So I think I have a better chance at getting it to work via the command line.

I have tried:

g++ test.cpp -lglfw or g++ test.cpp -LC:\GLFW\lib -lglfw  

into the command line.

回答1:

A simple investigate of the GLFW3's lib-mingw directory holds the answer for your question. Say you've GLFW3's binary package, from here (one of glfw-3.0.3.bin.WIN64.zip or glfw-3.0.3.bin.WIN32.zip depending on your toolchain). Extracting it should've given a directory lib-mingw amongst others. This directory contains:

  • libglfw3.a
  • glfw3dll.a
  • glfw3.dll

Thus the library name is glfw3 and not just glfw. So when passing it to the linker, you've to pass -lglfw3 i.e. if you want to statically link to it. If you want to link to it dynamically, then just pass glfw3dll.a; adding the -l will lead to the linker prefixing it with lib and suffixing it with .a (see Django's answer).



回答2:

I managed to make mingw32 and GLFW3 to work together.

  1. Be sure you have consistent librairies (32 or 64 bits) (it wasn't my case)
  2. Rename glfw3dll.a to libglfw3dll.a
  3. Add you lib*.a from glfw to %MINGW_BASE%\lib and include files to %MINGW_BASE%\include
  4. Compile and link using g++ test.cpp -lglfw3 -lopengl32
  5. To run it, be sure to add glfw3.dll in System32 or/and SysWOW64

It worked for me

Hope it will help,



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!