简体   繁体   English

如何在 MinGW-w64 上运行 freeglut 3.2.1 和 GLEW 2.1.0?

[英]How can I have freeglut 3.2.1 and GLEW 2.1.0 run on MinGW-w64?

I'm a bit new to programming, and I'm trying to get an OpenGL program to run on a X64bit C++ compiler.我对编程有点陌生,我正在尝试让 OpenGL 程序在 X64 位 C++ 编译器上运行。 The code worked on MinGW - Minimalist GNU for Windows with the freeglut 3.0.0 MinGW Package installed on it.该代码适用于 MinGW - 安装了freeglut 3.0.0 MinGW Package的 Windows 的极简 GNU

I'm trying to have my program work with:我正在尝试让我的程序与:

  1. MinGW-w64 that I installed following these stackoverflow instructions .我按照这些stackoverflow 说明安装的 MinGW-w64。
  2. And freeglut 3.2.1 and GLEW 2.1.0 that I also installed following these medium.com instructions (skipping Steps 1-3 because I already had CLion's cmake and MinGW-w64 installed).我还按照这些介质安装了 freeglut 3.2.1 和 GLEW 2.1.0。com 说明(跳过步骤 1-3,因为我已经安装了 CLion 的 cmake 和 MinGW-w64)。

It shows that it all installed correctly as the instructions explained.表明它已按照说明正确安装。

I then updated the MinGW selected to be MinGW-w64 in my CLion editor (File>Settings>Build, Execute, Deployment>Toolchains), and hit the build button.然后我在我的 CLion 编辑器(文件>设置>构建、执行、部署>工具链)中更新了选择为 MinGW-w64 的 MinGW,然后点击构建按钮。 Bellow are the errors that it gave.下面是它给出的错误。

In my CMakeLists.txt I have target_link_libraries(SnakeGame_run SnakeGame_lib -lopengl32 -lglew32 -lfreeglut -lglu32) .在我的 CMakeLists.txt 我有target_link_libraries(SnakeGame_run SnakeGame_lib -lopengl32 -lglew32 -lfreeglut -lglu32) And in the code, wherever I use the #include <GL/freeglut.h> I have #include <GL/glew.h> included before it.在代码中,无论我在哪里使用#include <GL/freeglut.h> ,我都在它之前包含了#include <GL/glew.h> To my knowledge, I have it all setup to work, but it won't link freeglut nor GLEW at compile time (if I understand right).据我所知,我已经完成了所有设置,但它不会在编译时链接 freeglut 或 GLEW(如果我理解正确的话)。

How can I make these two libraries compatible?如何使这两个库兼容?

"C:\...\JetBrains\CLion 2019.3.4\bin\cmake\win\bin\cmake.exe" --build C:\...\Snake-Game\cmake-build-debug --target SnakeGame_run -- -j 9
[ 81%] Built target SnakeGame_lib
[90%] Linking CXX executable SnakeGame_run.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libglew32.dll.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libglew32.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib\libglew32.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/libglew32.dll.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/libglew32.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib\libglew32.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libglew32.dll.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libglew32.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/libglew32.dll.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/libglew32.a when searching for -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglew32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libfreeglut.dll.a when searching for -lfreeglut
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/libfreeglut.dll.a when searching for -lfreeglut
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libfreeglut.dll.a when searching for -lfreeglut
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/libfreeglut.dll.a when searching for -lfreeglut
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lfreeglut

So, if you're having such troubles linking GLEW and freeglut dynamically, I suggest you could build the libraries yourself and link statically.因此,如果您在动态链接 GLEW 和 freeglut 时遇到麻烦,我建议您可以自己构建库并静态链接。

Building GLEW建造 GLEW

Assuming you've got MSYS2/Mingw-w64 toolchain installed, download the GLEW sources from the medium link you included and build the library according to README instruction:假设您已安装 MSYS2/Mingw-w64 工具链,请从您包含的媒体链接下载 GLEW 源代码,并根据 README 说明构建库:

#### MSYS2/Mingw-w64

Available from [Msys2](http://msys2.github.io/) and/or [Mingw-w64](http://mingw-w64.org/)

Requirements: bash, make, gcc

    $ pacman -S gcc make  mingw-w64-i686-gcc mingw-w64-x86_64-gcc 
    $ make
    $ make install
    $ make install.all

You could omit installation, as we'll be passing library path later on anyway.您可以省略安装,因为我们稍后将传递库路径。 Just make sure that glew library has showed up in /lib directory after make .只需确保 glew 库在make之后出现在 /lib 目录中即可。

Building/linking freeglut构建/链接 freeglut

As for the freeglut, I suggest downloading the binaries from here: https://www.transmissionzero.co.uk/software/freeglut-devel/ (freeglut 3.0.0 MinGW Package - https://www.transmissionzero.co.uk/files/software/development/GLUT/freeglut-MinGW.zip ). As for the freeglut, I suggest downloading the binaries from here: https://www.transmissionzero.co.uk/software/freeglut-devel/ (freeglut 3.0.0 MinGW Package - https://www.transmissionzero.co.uk /files/software/development/GLUT/freeglut-MinGW.zip )。 After unzipping the package, there's a /lib folder with x64 directory inside.解压 package 后,有一个 /lib 文件夹,里面有 x64 目录。 So, we'll be linking against these libraries.因此,我们将链接这些库。 As the name suggests, they are for x64 architecture.顾名思义,它们适用于 x64 架构。

Linking it together将其连接在一起

This is not best practice to explicitly put library names within target_link_libraries , but let's stick to it.将库名称显式放入target_link_libraries并不是最佳实践,但让我们坚持下去。 If it works, it could be refactored a bit later.如果它有效,它可以稍后重构。

This is your cmake command so far: target_link_libraries(SnakeGame_run SnakeGame_lib -lopengl32 -lglew32 -lfreeglut -lglu32) Now, lopengl32 and lglu32 seem to be linking properly, problem is with lglew32 and lfreeglut, but in previous steps we made sure that we've got x64 binaries for sure.到目前为止,这是您的 cmake 命令: target_link_libraries(SnakeGame_run SnakeGame_lib -lopengl32 -lglew32 -lfreeglut -lglu32)现在,lopengl32 和 lglu32 似乎链接正确,问题出在 lglew32 和 lfreeglut,但在前面的步骤中,我们确保我们已经肯定有 x64 二进制文件。 But now we've to make sure that your application links with proper libraries, thus for purpose of testing, CMake allows us to specify full path to a library ( https://cmake.org/cmake/help/v3.3/command/target_link_libraries.html ).但是现在我们必须确保您的应用程序与正确的库链接,因此为了测试目的,CMake 允许我们指定库的完整路径( https://cmake.org/cmake/help/v3.3/command /target_link_libraries.html )。 So, assuming GLEW is in C:\Projects\my_downloaded_glew and built library showed up as C:\Projects\my_downloaded_glew\lib\libglew32 , we have to replace -lglew32 with C:\Projects\my_downloaded_glew\lib\libglew32 . So, assuming GLEW is in C:\Projects\my_downloaded_glew and built library showed up as C:\Projects\my_downloaded_glew\lib\libglew32 , we have to replace -lglew32 with C:\Projects\my_downloaded_glew\lib\libglew32 . Now, after downloading freeglut, I assume downloaded GLUT binaries are in C:\Projects\my_downloaded_freeglut\lib\x64\ , thus -lfreeglut will have to be replaced with C:\Projects\my_downloaded_freeglut\lib\x64\libfreeglut .现在,在下载 freeglut 之后,我假设下载的 GLUT 二进制文件在C:\Projects\my_downloaded_freeglut\lib\x64\中,因此-lfreeglut必须替换为C:\Projects\my_downloaded_freeglut\lib\x64\libfreeglut Putting it all together, it'd try the following:将它们放在一起,它会尝试以下操作:

target_link_libraries(SnakeGame_run SnakeGame_lib -lopengl32 C:\Projects\my_downloaded_glew\lib\libglew32 C:\Projects\my_downloaded_freeglut\lib\x64\libfreeglut -lglu32)

I believe the headers you have installed should be compatible.我相信您安装的标头应该是兼容的。

Let me know if it helped.让我知道它是否有帮助。

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

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