c++openglmingwglfwglew

MinGW Linker error while trying to build GLEW project, despite library (glew32.a) seems to be fine


I have an issue linking my OpenGL project using Cmake.

To use OpenGL extensions, I downloaded the prebuilt GLEW library binaries. But after building my project, I`ve got a bunch of warnings:

skipping incompatible C:/Users/.../lib when searching for -lglew32"

For all of the 4 binaries, I've tried to link (glew32.a, glew32.dll.a, glew32mx.dll.a, glew32mx.a). As a result, the required library is not found, and the linkage fails.

My CmakeList:

cmake_minimum_required(VERSION 3.17)
project(Graphics)

set(CMAKE_CXX_STANDARD 14)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/OpenGL/include/GLFW)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/OpenGL/lib/GLFW)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/OpenGL/include/GLEW)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/OpenGL/lib/GLEW)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/OpenGL/include/GL)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/OpenGL/lib/Freeglut)

include_directories(include)

add_executable(Graphics main.cpp)

set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_FLAGS -m32)

target_link_libraries(Graphics glu32 OpenGL32 libglew32mx.dll.a freeglut libglfw3.a)

add_custom_target(freeglutdll
        COMMAND ${CMAKE_COMMAND} -E copy
        ${PROJECT_SOURCE_DIR}/OpenGL/bin/freeglut.dll ${CMAKE_BINARY_DIR}
        )

add_custom_target(glew32mxdll
        COMMAND ${CMAKE_COMMAND} -E copy
        ${PROJECT_SOURCE_DIR}/OpenGL/bin/glew32mx.dll ${CMAKE_BINARY_DIR}
        )

add_custom_target(glew32dll
        COMMAND ${CMAKE_COMMAND} -E copy
        ${PROJECT_SOURCE_DIR}/OpenGL/bin/glew32.dll ${CMAKE_BINARY_DIR}
        )

add_custom_target(glfw3dll
        COMMAND ${CMAKE_COMMAND} -E copy
        ${PROJECT_SOURCE_DIR}/OpenGL/bin/glfw3.dll ${CMAKE_BINARY_DIR}
        )

add_dependencies(Graphics glew32mxdll)
add_dependencies(Graphics glew32dll)
add_dependencies(Graphics freeglutdll)
add_dependencies(Graphics glfw3dll)

The code I'm trying to compile is pretty simple:

#include "OpenGL/include/GL/freeglut.h"
#include "OpenGL/include/GLEW/glew.h"
#include "OpenGL/include/GLFW/glfw3.h"
#include <iostream>
#include <cstdio>

int main(int argc, const char **argv)
{
    if (!glfwInit())
    {
        std::cerr << "Error while initializing glfw" << std::endl;
        return -1;
    }
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    GLFWwindow *window = glfwCreateWindow(1280, 720, "Voxel", nullptr, nullptr);
    if (window == nullptr)
    {
        std::cerr << "Error creating window" << std::endl;
        return 1;
    }
    glfwMakeContextCurrent(window);

    glewExperimental = true;
    if (glewInit() != GLEW_OK)
    {
        std::cerr << "Error while initializing glew" << std::endl;
        return -1;
    }
    return 0;
}

The full compilation log is as follows:

====================[ Build | Graphics | Debug ]================================
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" --build "C:\Users\Anton\C++ project\Graphics\cmake-build-debug" --target Graphics -- -j 6
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Anton/C++ project/Graphics/cmake-build-debug
[  0%] Built target freeglutdll
[  0%] Built target glfw3dll
[ 50%] Linking CXX executable Graphics.exe
C:/PROGRA~2/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Users/Anton/C__PRO~1/Graphics/OpenGL/lib/GLEW/libglew32mx.dll.a when searching for -lglew32mx
C:/PROGRA~2/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Users/Anton/C__PRO~1/Graphics/OpenGL/lib/GLEW/libglew32mx.a when searching for -lglew32mx
C:/PROGRA~2/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Users/Anton/C__PRO~1/Graphics/OpenGL/lib/GLEW/glew32mx.dll when searching for -lglew32mx
C:/PROGRA~2/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Users/Anton/C__PRO~1/Graphics/OpenGL/lib/GLEW\libglew32mx.a when searching for -lglew32mx
C:/PROGRA~2/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Users/Anton/C__PRO~1/Graphics/OpenGL/lib/GLEW/libglew32mx.dll.a when searching for -lglew32mx
C:/PROGRA~2/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Users/Anton/C__PRO~1/Graphics/OpenGL/lib/GLEW/libglew32mx.a when searching for -lglew32mx
C:/PROGRA~2/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/Users/Anton/C__PRO~1/Graphics/OpenGL/lib/GLEW/glew32mx.dll when searching for -lglew32mx
C:/PROGRA~2/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglew32mx
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Graphics.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Graphics.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Graphics.dir/rule] Error 2
mingw32-make.exe: *** [Graphics] Error 2
CMakeFiles\Graphics.dir\build.make:105: recipe for target 'Graphics.exe' failed
CMakeFiles\Makefile2:97: recipe for target 'CMakeFiles/Graphics.dir/all' failed
CMakeFiles\Makefile2:104: recipe for target 'CMakeFiles/Graphics.dir/rule' failed
Makefile:137: recipe for target 'Graphics' failed

What may I be doing wrong and how can I fix it?


Solution

  • Well, I solved this problem pretty simple - just used pre build .lib file and defined GLEW_STATIC at the beginning