【问题标题】:How can I solve `glew32.dll is missing from your computer` issue of my OpenGL program?如何解决我的 OpenGL 程序的 `glew32.dll is missing from your computer` 问题?
【发布时间】:2021-12-14 08:52:37
【问题描述】:

当我尝试构建和运行我的 OpenGL+GLEW+GLFW 程序时,它构建得很好但不会运行,给我这个错误:"The program can't start because glew32.dll is missing from your computer. Try reinstalling the program to fix this problem."

我将glew32.lib 链接为静态库。我也在使用#define GLEW_STATIC

那么,为什么程序会提示输入 DLL 文件呢?

#include <iostream>

//#define GLEW_STATIC

// GLEW
#include <include/GL/glew.h>

// GLFW
#include <include/GLFW/glfw3.h>

//we define GLEW_STATIC, since we’re using the static version of the GLEW library.
#define GLEW_STATIC


// Is called whenever a key is pressed/released via GLFW
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
    std::cout << key << std::endl;

    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
    {
        //we close GLFW by setting its WindowShouldClose 
        //property to true.
        glfwSetWindowShouldClose(window, GL_TRUE);
    }
}

// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;

// The MAIN function, from here we start the application and run the game loop
int main()
{
    std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
    // Initializes GLFW
    glfwInit();
    // Set all the required options for GLFW
    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);

    // Create a GLFWwindow object that we can use for GLFW's functions
    GLFWwindow * window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
    glfwMakeContextCurrent(window);
    if (window == NULL)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }

    // Set the required callback functions
    glfwSetKeyCallback(window, key_callback);

    // Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
    glewExperimental = GL_TRUE;
    // Initialize GLEW to setup the OpenGL Function pointers
    if (glewInit() != GLEW_OK)
    {
        std::cout << "Failed to initialize GLEW" << std::endl;
        return -1;
    }    

    // Define the viewport dimensions
    glViewport(0, 0, WIDTH, HEIGHT);

    // Game loop
    while (!glfwWindowShouldClose(window))
    {
        // Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
        glfwPollEvents();

        // Render
        // Clear the colorbuffer
        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        // Swap the screen buffers
        glfwSwapBuffers(window);
    }

    // Terminate GLFW, clearing any resources allocated by GLFW.
    glfwTerminate();
    return 0;
}

【问题讨论】:

  • #defining GLEW_STATIC after #include glew.h 不会有任何效果。它只在这个文件中有意义。

标签: opengl dll glew


【解决方案1】:

我正在链接 glew32.lib

这就是你出错的地方,glew32.lib 是 DLL 版本的导入库。如果您不想依赖 glew32.dll,那么您需要链接静态链接库。它的名字是glew32s.lib。否则定义 GLEW_STATIC 对此没有影响。

猜测这可能会出错,请注意 SourceForge 提供的预构建二进制文件仅包括 glew32.lib。您必须自己构建 glew32s.lib。这通常是一个非常硬的要求,使用与构建其余代码完全相同的编译器版本和编译器选项非常重要。阅读项目的 readme.txt 文件以获取构建说明,我从提供的项目文件中使用 MSVC 构建没有任何问题。

库名称的完整列表:

  • glew32.lib:发布版本,需要 glew32.dll
  • glew32d.lib:调试版本,需要glew32d.dll
  • glew32s.lib:发布版本,静态链接库
  • glew32sd.lib:调试构建,静态链接库

您还可以选择构建这些库的 MX(多渲染上下文)版本,“mx”附加到它们的名称。

【讨论】:

    【解决方案2】:

    从这里下载 glew http://glew.sourceforge.net/
    解压吧
    进入glew-1.13.0\bin\Release\Win32(glew-1.13.0是glew的文件夹,你解压出来)
    有一个名为“glew32.dll”的文件
    将“glew32.dll”复制到 Visual Studio 项目中的 Debug 文件夹
    C:\Users\Thien\Documents\Visual Studio 2015\Projects\your_project_name\Debug

    然后按f5运行

    【讨论】:

      【解决方案3】:

      glew32.dll 不是标准 DLL。使用它的其他程序很有可能静态链接它或将 DLL 安装在其可执行文件旁边。我建议您将 GLEW 静态链接到您的程序。 http://glew.sourceforge.net/install.html 记录了如何进行静态或动态链接构建。

      【讨论】:

        【解决方案4】:

        您可能必须将 glew32.dll 文件放在 C:\Windows\System32 文件夹中。

        【讨论】:

          【解决方案5】:
          1. 检查文件夹glew-2.1.0-win32\glew-2.1.0\bin\Release\x64下是否存在glew32.dll;
          2. glew-2.1.0-win32\glew-2.1.0\bin\Release\x64完整绝对路径添加到环境变量路径中。

          【讨论】:

            【解决方案6】:

            如果您使用的是 Visual Studio,我通过进入项目 -> 属性 -> c/c++ -> 预处理器 -> 预处理器定义并添加 GLEW_STATIC 解决了这个问题,当然如果您使用的是 glew32s.lib 或在 glew.h 的每个包含之前使用#define GLEW_STATIC

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2023-01-31
              • 2019-08-13
              • 2021-11-21
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多