您是否可以向我解释为什么在构建以下程序时添加“legacy_stdio_definitions.lib”可以解决错误? 当我试图使用GLFW库时发生错误。 我对C++和OpenGL世界还很陌生,经过几个小时的在线搜索和数小时的试验和错误,我偶然发现了将“legacy_stdio_definitions.lib”添加到其他依赖关系的建议。这确实解决了错误,但我仍然不完全明白问题是什么以及.lib做了什么来解决它。通过添加legacy_stdio_definitions.lib解决了C++ GLFW错误。为什么?
我正在使用Microsoft Visual Studio 2015社区版btw。
所有我做的步骤是:
- C/C++ - >常规加入包括用于GLEW,GLM和GLFW
- 链接器>常规添加GLEW和GLFW库
- 链接器>输入添加 glew32.lib,glfw3.lib和legacy_stdio_definitions.lib
- 添加glew32.dll到我的项目文件夹
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
using namespace glm;
int main() {
// Initialise GLFW
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
// Open a window and create its OpenGL context
GLFWwindow* window; // (In the accompanying source code, this variable is global)
window = glfwCreateWindow(1024, 768, "Tutorial 01", NULL, NULL);
if (window == NULL) {
fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window); // Initialize GLEW
glewExperimental = true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
do {
// Draw nothing, see you in tutorial 2 !
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
} // Check if the ESC key was pressed or the window was closed
while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0);
}
任何帮助将不胜感激。
这是一个VS2015问题:https://msdn.microsoft.com/en-us/library/bb531344.aspx。可能你正在使用一个已编译的glew或glfw库,它是用以前的VS版本编译的。尝试自己编译glew和glfw。 – Ripi2