Note that there are some explanatory texts on larger screens.

plurals
  1. POLots of undeclared identifiers related to OpenGL using GLFW
    text
    copied!<p>I'm trying to set up an OpenGL project using GLFW in Visual c++ 2008 (Windows 7). I have added the GLFW include and library directories to the project's include and library paths, and I have put the following in additional dependencies:</p> <pre><code>GLFW.lib glu32.lib opengl32.lib </code></pre> <p>That is everything I need to do, isn't it? But when I try to compile any OpenGl program (except an extremely simple one that only clears the screen using glClear) I get a bunch of undeclared identifier and identifier not found erros. Any Idea why this can happen? Here is the complete error list: </p> <pre><code>1&gt;Compiling... 1&gt;main.cpp 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(9) : error C2146: syntax error : missing ';' before identifier 'VBO' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(9) : error C2377: 'GLuint' : redefinition; typedef cannot be overloaded with any other symbol 1&gt; c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(52) : see declaration of 'GLuint' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(43) : error C3861: 'glEnableVertexAttribArray': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(45) : error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(45) : error C3861: 'glBindBuffer': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(47) : error C3861: 'glVertexAttribPointer': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(55) : error C3861: 'glDisableVertexAttribArray': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(78) : error C3861: 'glGenBuffers': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(80) : error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(80) : error C3861: 'glBindBuffer': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(82) : error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(82) : error C2065: 'GL_STATIC_DRAW' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(82) : error C3861: 'glBufferData': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(87) : error C2146: syntax error : missing ')' before identifier 'ShaderProgram' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(87) : error C2182: 'AddShader' : illegal use of type 'void' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(87) : error C2440: 'initializing' : cannot convert from 'Vector3f' to 'int' 1&gt; No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(87) : error C2059: syntax error : ')' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(89) : error C2143: syntax error : missing ';' before '{' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(89) : error C2447: '{' : missing function header (old-style formal list?) 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(144) : error C2146: syntax error : missing ';' before identifier 'ShaderProgram' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(144) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(144) : error C3861: 'glCreateProgram': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(148) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(158) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(158) : error C2065: 'GL_VERTEX_SHADER' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(160) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(160) : error C2065: 'GL_FRAGMENT_SHADER' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2065: 'GLchar' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2146: syntax error : missing ';' before identifier 'ErrorLog' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2065: 'ErrorLog' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2059: syntax error : '{' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2143: syntax error : missing ';' before '{' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2143: syntax error : missing ';' before '}' 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(170) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(170) : error C3861: 'glLinkProgram': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(172) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(172) : error C2065: 'GL_LINK_STATUS' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(172) : error C3861: 'glGetProgramiv': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C2065: 'ErrorLog' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C2070: ''unknown-type'': illegal sizeof operand 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C2065: 'ErrorLog' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C3861: 'glGetProgramInfoLog': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(178) : error C2065: 'ErrorLog' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(186) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(186) : error C3861: 'glValidateProgram': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(188) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(188) : error C2065: 'GL_VALIDATE_STATUS' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(188) : error C3861: 'glGetProgramiv': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C2065: 'ErrorLog' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C2070: ''unknown-type'': illegal sizeof operand 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C2065: 'ErrorLog' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C3861: 'glGetProgramInfoLog': identifier not found 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(194) : error C2065: 'ErrorLog' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(202) : error C2065: 'ShaderProgram' : undeclared identifier 1&gt;c:\glfw-2.7.3\opengl ikasi\main.cpp(202) : error C3861: 'glUseProgram': identifier not found </code></pre> <p>EDIT: here is the whole program</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;GL/glfw.h&gt; #include "math_3d.h" GLuint VBO; static const char* pVS = " \n\ #version 150 \n\ \n\ layout (location = 0) in vec3 Position; \n\ \n\ void main() \n\ { \n\ gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0); \n\ }"; static const char* pFS = " \n\ #version 150 \n\ \n\ out vec4 FragColor; \n\ \n\ void main() \n\ { \n\ FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n\ }"; static void RenderSceneCB() { glClear(GL_COLOR_BUFFER_BIT); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, VBO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(0); glfwSwapBuffers(); } static void CreateVertexBuffer() { Vector3f Vertices[3]; Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f); Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f); Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f); glGenBuffers(1, &amp;VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW); } static void AddShader(GLuint ShaderProgram, const char* pShaderText, GLenum ShaderType) { GLuint ShaderObj = glCreateShader(ShaderType); if (ShaderObj == 0) { fprintf(stderr, "Error creating shader type %d\n", ShaderType); return ; } const GLchar* p[1]; p[0] = pShaderText; GLint Lengths[1]; Lengths[0]= strlen(pShaderText); glShaderSource(ShaderObj, 1, p, Lengths); glCompileShader(ShaderObj); GLint success; glGetShaderiv(ShaderObj, GL_COMPILE_STATUS, &amp;success); if (!success) { GLchar InfoLog[1024]; glGetShaderInfoLog(ShaderObj, 1024, NULL, InfoLog); fprintf(stderr, "Error compiling shader type %d: '%s'\n", ShaderType, InfoLog); return; } glAttachShader(ShaderProgram, ShaderObj); } static void CompileShaders() { GLuint ShaderProgram = glCreateProgram(); if (ShaderProgram == 0) { fprintf(stderr, "Error creating shader program\n"); return; } AddShader(ShaderProgram, pVS, GL_VERTEX_SHADER); AddShader(ShaderProgram, pFS, GL_FRAGMENT_SHADER); GLint Success = 0; GLchar ErrorLog[1024] = { 0 }; glLinkProgram(ShaderProgram); glGetProgramiv(ShaderProgram, GL_LINK_STATUS, &amp;Success); if (Success == 0) { glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog); fprintf(stderr, "Error linking shader program: '%s'\n", ErrorLog); return; } glValidateProgram(ShaderProgram); glGetProgramiv(ShaderProgram, GL_VALIDATE_STATUS, &amp;Success); if (!Success) { glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog); fprintf(stderr, "Invalid shader program: '%s'\n", ErrorLog); return; } glUseProgram(ShaderProgram); } int main(int argc, char** argv) { glfwInit(); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindow(600, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); CreateVertexBuffer(); CompileShaders(); while (1) { RenderSceneCB(); } return 0; } </code></pre> <p>EDIT 2: And here the math_3d.h header</p> <pre><code>#ifndef MATH_3D_H #define MATH_3D_H struct Vector3f { float x; float y; float z; Vector3f() { } Vector3f(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } }; #endif </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload