您是否可以向我解釋爲什麼在構建以下程序時添加「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