How can I solve `glew32.dll is missing from your computer` issue of my OpenGL program?
Asked Answered
E

6

11

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."

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

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;
}
Everick answered 10/3, 2014 at 16:48 Comment(1)
#defining GLEW_STATIC after #including glew.h won't have any effect. It only have meaning inside this file.Wyckoff
C
14

I am linking glew32.lib

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.

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.

The full list of library names:

  • 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

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

Chinn answered 1/1, 2016 at 17:24 Comment(0)
D
11

Download glew from here http://glew.sourceforge.net/
Unzip it
Go to glew-1.13.0\bin\Release\Win32 (glew-1.13.0 is a folder of glew you just unzip)
There is a file named "glew32.dll"
Copy "glew32.dll" to the Debug folder in your visual studio project
C:\Users\Thien\Documents\Visual Studio 2015\Projects\your_project_name\Debug

Then press f5 to run

Donegan answered 14/1, 2016 at 15:45 Comment(0)
H
3

glew32.dll is not a standard DLL. There's a high probability that the other programs using it either link it statically or have the DLL installed beside their executable. I suggest you link GLEW statically to your program. At http://glew.sourceforge.net/install.html it is documented how to do either statically or dynamically linked builds.

Highspirited answered 10/3, 2014 at 17:13 Comment(0)
C
2

if you are using visual studio I fixed this problem by going into project-> properties -> c/c++ -> Preprocessor -> Preprocessor Definitions and added GLEW_STATIC This of course if you are using glew32s.lib or use #define GLEW_STATIC before every include of glew.h

Cheerless answered 14/12, 2021 at 0:35 Comment(0)
W
0

You may have to put the glew32.dll file in the C:\Windows\System32 folder.

Wham answered 15/5, 2017 at 9:42 Comment(0)
D
0
  1. Check if glew32.dll exits under folder glew-2.1.0-win32\glew-2.1.0\bin\Release\x64;
  2. Add the full absolute path of glew-2.1.0-win32\glew-2.1.0\bin\Release\x64 to environment variables path.
Dragonet answered 16/2, 2019 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.