我的OpenGL程序如何解决`glew32.dll的问题? [英] How can I solve `glew32.dll is missing from your computer` issue of my OpenGL program?

查看:1433
本文介绍了我的OpenGL程序如何解决`glew32.dll的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我正在构建并运行我的OpenGL + GLEW + GLFW程序时,它构建的很好,但不会运行,给我这个错误:该程序无法启动,因为glew32.dll从您的计算机中丢失,请尝试重新安装程序来解决此问题。

When I'm trying to build and run my OpenGL+GLEW+GLFW program, it builds just fine but wont run, giving me this error : "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

I am linking glew32.lib as a static library. I am also using #define GLEW_STATIC.

那么为什么程序会提示一个DLL文件? p>

Then, why is the program prompting for a DLL file?

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


推荐答案


我正在链接glew32.lib

I am linking glew32.lib

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

That's where you went wrong, glew32.lib is the import library for the DLL version. If you don't want a dependency on glew32.dll then you need to link the static link library. Its name is glew32s.lib. Defining GLEW_STATIC otherwise has no effect on this.

猜测这可能会出错,请注意SourceForge上提供的预构建二进制文件只包含glew32.lib。你必须自己建立glew32s.lib。这通常是一个非常困难的要求,使用完全相同的编译器版本和编译器选项来构建其余的代码是非常重要的。阅读项目的readme.txt文件以进行构建指令,我从提供的项目文件中无缝构建MSVC。

Guessing how this could have gone wrong, beware that the pre-built binaries available at SourceForge only include glew32.lib. You'll have to build glew32s.lib yourself. Which is in general a pretty hard requirement, it is very important that you use the exact same compiler version and compiler options you use to build to the rest of your code. Read the project's readme.txt file for build instructions, I had no trouble whatsoever building with MSVC from the provided project files.

库名称的完整列表:


  • glew32.lib:发布版本,需要glew32.dll

  • glew32d.lib:调试版本,需要glew32d .dll

  • glew32s.lib:发布版本,静态链接库

  • glew32sd.lib:调试版本,静态链接库

  • glew32.lib: release build, requires glew32.dll
  • glew32d.lib: debug build, requires glew32d.dll
  • glew32s.lib: release build, static link library
  • glew32sd.lib: debug build, static link library

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

You can optionally also build the MX (multiple rendering context) versions of these libraries, "mx" is appended to their names.

这篇关于我的OpenGL程序如何解决`glew32.dll的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆