尽管库 (glew32.a) 似乎没问题,但在尝试构建 OpenGl 项目时出现错误(跳过不兼容)

Getting error (skipping incompatible) while trying to build OpenGl project, despite library (glew32.a) seems to be fine

我在使用 Cmake(来自 Clion)构建我的 OpenGL 代码时遇到问题。

首先,我从官方网站下载了预构建二进制文件,但问题是 glew32.lib 没有 _imp__glewExperimental,所以在阅读了一些论坛后我想出了一个解决方案自己建一个图书馆。但是在构建之后,我开始得到:

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

对于我尝试过的任何库 link(glew32.a、glew32.dll.a、glew32mx.dll.a、glew32mx.a)。

我的 CmakeList:

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)

我要编译的代码非常简单:

#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;
}

我得到的完整错误:

====================[ 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

我做错了什么?

好吧,我很简单地解决了这个问题 - 只是使用预构建 .lib 文件并在开头定义了 GLEW_STATIC