当我尝试构建并运行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;
}
请您参考如下方法:
I am linking glew32.lib
这就是您出错的地方,glew32.lib是DLL版本的导入库。如果您不希望依赖glew32.dll,则需要链接静态链接库。它的名称是
glew32s.lib 。否则定义GLEW_STATIC对此没有任何影响。
猜测这怎么可能出错,请注意SourceForge上可用的预构建二进制文件仅包含glew32.lib。您必须自己构建glew32s.lib。通常,这是一个非常困难的要求,非常重要的一点是,您要使用与构建其余代码完全相同的编译器版本和编译器选项。阅读项目的readme.txt文件以获取构建说明,无论从提供的项目文件中使用MSVC进行构建,我都没有遇到任何麻烦。
库名称的完整列表:
您还可以选择构建这些库的MX(多个渲染上下文)版本,在它们的名称后附加“mx”。




