opengl 项目链接错误,而试图建立GLEW项目,尽管库(glew32.a)似乎是好的

unftdfkk  于 2023-10-18  发布在  其他
关注(0)|答案(1)|浏览(99)

我在使用Cmake链接OpenGL项目时遇到问题。
为了使用OpenGL扩展,我下载了预构建的GLEW库二进制文件。但在构建我的项目后,我得到了一个警告:

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

对于所有4个二进制文件,我都尝试链接(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

我做错了什么?

x759pob2

x759pob21#

我很简单地解决了这个问题--只需要使用prebuild.lib文件并在开始时定义GLEW_STATIC

相关问题