0

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
  • It appears that your target (SnakeGame_lib) is indeed built for 64-bits, yet for some reason you decided to link it explicitly with 32-bit libraries ( lopengl32, lglew32 etc.). I think it won't be possible. Could you change them to 64-bit? Or omit the architecture at all? – Marek Piotrowski Aug 17 '20 at 21:35
  • How do you change them to 64-bit? What do you mean by omitting the architecture? Do you mean to drop OpenGL and go with a different graphics library for c++? – happyPenguin Aug 18 '20 at 15:06
  • `-lopengl` instead of `-lopengl32` etc. – Marek Piotrowski Aug 18 '20 at 15:23
  • No, it just says this for them if I do that. ```C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lopengl``` – happyPenguin Aug 18 '20 at 15:28
  • Considering you build it on windows, this might help you: https://stackoverflow.com/questions/1236670/how-to-make-opengl-apps-in-64-bit-windows. It appears that you should be looking for glew somewhere else. But I see that due to historic reasons even 64bit OpenGL is called OpenGL32. – Marek Piotrowski Aug 18 '20 at 15:40
  • Yeah, that's what I read too about the historic name... so misleading. – happyPenguin Aug 18 '20 at 16:14
  • I don't know what to do. I tried everything from that [stackoverflow question](https://stackoverflow.com/questions/1236670/how-to-make-opengl-apps-in-64-bit-windows), but I still get the ```skipping incompatibility``` error. I tried adding ```Opengl32.lib glu32.dll``` and a bunch of other combinations in the CMake ```target_link_libraries()``` function. – happyPenguin Aug 18 '20 at 21:28

1 Answers1

0

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.

Marek Piotrowski
  • 2,988
  • 3
  • 11
  • 16
  • Sorry Marek, I got really busy with other projects and had to put this one on the back-burner. I will let you know if your solution worked for me when I get to it. Thank you. – happyPenguin Sep 04 '20 at 19:46