当我试图测试我是否正确地安装了GLFW以便与VS2010一起使用时,我得到了“未声明的标识符”和“未声明的标识符”编译器错误。
我从GLFW下载了用于Visual Studio2010的最新32位二进制文件。
glfw3.h和glfw3native.h头文件位于Windows SDK文件夹的include/gl文件夹和VS2010安装的include文件夹中。
lib和glfw3dll.lib文件位于Windows SDK的lib文件夹和VS2010安装的lib文件夹中。
file文件与我的VS2010项目的.exe和我的System32文件夹在同一个文件夹中。
重复位置的存在是为了确定问题是否在于我的项目没有指向正确的include、lib目录。
在链接器->附加依赖项中,我有glfw3.lib、glew32d.lib、opengl32.lib和lu32.lib。我尝试单独包含glfw3dll.lib,并将其与glfw3.lib结合使用,结果相同。
以下是构建日志:
Build started 7/20/2013 01:00:28.
1>Project "j:\Users\Guy\documents\visual studio 2010\Projects\OpenGL4Test\OpenGL4Test\OpenGL4Test.vcxproj" on node 2 (build target(s)).
1>InitializeBuildStatus:
Touching "Debug\OpenGL4Test.unsuccessfulbuild".
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt main.cpp
main.cpp
1>j:\users\Guy\documents\visual studio 2010\projects\opengl4test\opengl4test\main.cpp(13): error C2065: 'GLFW_OPENGL_VERSION_MAJOR' : undeclared identifier
1>j:\users\Guy\documents\visual studio 2010\projects\opengl4test\opengl4test\main.cpp(13): error C3861: 'glfwOpenWindowHint': identifier not found
1>j:\users\Guy\documents\visual studio 2010\projects\opengl4test\opengl4test\main.cpp(14): error C2065: 'GLFW_OPENGL_VERSION_MINOR' : undeclared identifier
1>j:\users\Guy\documents\visual studio 2010\projects\opengl4test\opengl4test\main.cpp(14): error C3861: 'glfwOpenWindowHint': identifier not found
1>j:\users\Guy\documents\visual studio 2010\projects\opengl4test\opengl4test\main.cpp(15): error C3861: 'glfwOpenWindowHint': identifier not found
1>j:\users\Guy\documents\visual studio 2010\projects\opengl4test\opengl4test\main.cpp(16): error C3861: 'glfwOpenWindowHint': identifier not found
1>j:\users\Guy\documents\visual studio 2010\projects\opengl4test\opengl4test\main.cpp(19): error C2065: 'GLFW_WINDOW' : undeclared identifier
1>j:\users\Guy\documents\visual studio 2010\projects\opengl4test\opengl4test\main.cpp(19): error C3861: 'glfwOpenWindow': identifier not found
1>Done Building Project "j:\Users\Guy\documents\visual studio 2010\Projects\OpenGL4Test\OpenGL4Test\OpenGL4Test.vcxproj" (build target(s)) -- FAILED.
Build FAILED.
Time Elapsed 00:00:00.33代码来自OpenGL 4教程,我更改了GLFW头文件以反映最新的下载,即从glfw.h到glfw3.h:
#include <GL/glew.h> // include GLEW and new version of GL on Windows
#include <GL/glfw3.h> // GLFW helper library
#include <stdio.h>
#include <string>
int main () {
// start GL context and O/S window using the GLFW helper library
glfwInit ();
// "hint" that the version 4.2 should be run with no back-compat stuff
int major = 4;
int minor = 2;
glfwOpenWindowHint (GLFW_OPENGL_VERSION_MAJOR, major);
glfwOpenWindowHint (GLFW_OPENGL_VERSION_MINOR, minor);
glfwOpenWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// open a window of sixe 640x480 with 8bpp and 24 bits for depth sorting
glfwOpenWindow(640, 480, 8, 8, 8, 8, 24, 8, GLFW_WINDOW);
// start GLEW extension handler
glewInit ();
// get version info
const GLubyte* renderer = glGetString (GL_RENDERER); // get renderer string
const GLubyte* version = glGetString (GL_VERSION); // version as a string
printf("Renderer: %s\n", renderer);
printf("OpenGL version supported %s\n", version);
// tell GL to only draw onto a pixel if the shape is closer to the viewer
glEnable (GL_DEPTH_TEST); // enable depth-testing
glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer"
/* OTHER STUFF GOES HERE NEXT */
// close GL context and any other GLFW resources
glfwTerminate();
return 0;
}似乎大多数人都有链接这些库的问题,但这些都是编译器错误吗?
发布于 2013-07-20 18:20:21
在GLFW的版本3中,一些函数名称已更改,例如将glfwOpenWindowHint更改为glfwWindowHint。
此页提供了版本更改,因此使用CTRL F查找新的函数名称:
http://www.glfw.org/changelog.html
此外,我发现我需要将#include <GL/glfw3.h>更改为#include <GLFW/glfw3.h>,因为文件夹名称已更改(请查看GLFW目录以查看您的文件夹名称)。
希望这能帮上忙。
发布于 2013-12-30 18:13:53
现在没有什么比#include "GL/glfw3.h"更好的了。
如果您解压glfw包的源文件,您将获得文件夹GLFW,因此您需要将其包含如下所示
> #include "GLFW\glfw3.h"https://stackoverflow.com/questions/17758978
复制相似问题