与Visual Studio 2010链接后,glfw未声明的标识符

时间:2013-07-20 05:22:26

标签: visual-studio-2010 glfw

我正在获得未声明的标识符'和'标识符未声明'尝试测试我是否已正确安装GLFW以用于VS 2010时编译器错误。

我从GLFW下载了最新的32位二进制文​​件,以便与Visual Studio 2010一起使用。

glfw3.h和glfw3native.h头文件位于我的Windows SDKs文件夹的include / gl文件夹和我的VS 2010安装的include文件夹中。

glfw3.lib和glfw3dll.lib文件位于Windows SDKs lib文件夹和VS 2010安装的lib文件夹中。

glfw3.dll文件与我的VS 2010项目的.exe和我的System32文件夹位于同一文件夹中。

存在重复的位置以确定问题是我的项目是否指向正确的include,lib目录。

在Linker->附加依赖项中,我有glfw3.lib,glew32d.lib,opengl32.lib和glu32.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;
}

似乎大多数其他人在链接这些库时遇到问题,但这些是编译错误吗?

2 个答案:

答案 0 :(得分:1)

某些功能名称在GLFW的第3版中已更改,例如glfwOpenWindowHint更改为glfwWindowHint。

此页面提供版本更改,因此请使用CTRL F查找新的函数名称:

http://www.glfw.org/changelog.html

此外,我发现我需要将#include <GL/glfw3.h>更改为#include <GLFW/glfw3.h>,因为文件夹名称已更改(请检查GLFW目录以查看您的名称)。

希望有帮助...

答案 1 :(得分:0)

现在没有#include "GL/glfw3.h"

如果您提取glfw包的源文件,您将获得文件夹GLFW,因此您需要将其包含在内,如

> #include "GLFW\glfw3.h"