Search code examples
windowsclionmingw-w64glewfreeglut

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. The code worked on MinGW - Minimalist GNU for Windows with the freeglut 3.0.0 MinGW Package installed on it.

I'm trying to have my program work with:

  1. MinGW-w64 that I installed following these stackoverflow instructions.
  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).

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. Bellow are the errors that it gave.

In my CMakeLists.txt I have 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. 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).

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

Solution

  • So, if you're having such troubles linking GLEW and freeglut dynamically, I suggest you could build the libraries yourself and link statically.

    Building 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
    
    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.

    Building/linking 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). After unzipping the package, there's a /lib folder with x64 directory inside. So, we'll be linking against these libraries. As the name suggests, they are for x64 architecture.

    Linking it together

    This is not best practice to explicitly put library names within target_link_libraries, but let's stick to it. 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. 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). 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. 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.