0

So, as the title is pretty much explaining everything, let me tell why this does not work for me.

I have a simple OpenGL application which I am supposed to compile and run using GLFW libraries. So far so good, I have downloaded and tested all OpenGL and GLFW libaries, among other libraries like GLUT. When compiling the application through terminal, I also link the required libraries like so (I am not really sure which libararies required, that's why I put a bunch of them without a professional knowledge):

g++ -std=gnu++11 -lglut -lGL -lGLU -lGLEW -lglfw3 -lGL -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread main.cpp -o main -I external/include/

Let me share what ls shows on that project's directory:

external    gl_app.hpp       main.cpp    models.hpp
gl_app.cpp  gl_includes.hpp  models.cpp  Readme.md

The folder external includes some headers that were included in the main.cpp file. That is why I am also calling this folder.

Here is the first ten lines of main.cpp. The "glm/*.hpp" files are in the external folder.

#include "gl_app.hpp"
#include "models.hpp"

#include <glm/vec2.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include <iostream>
#include <memory>
#include <cmath>

And after all, here is the error message I get. It simply complains about the declarations. I have read many documentations and questions around, implementing many solutions of whom faced with very similar problem. Yet in my case the problem keeps remaining.

Any help?

main.cpp: In member function ‘virtual bool gl_ifi::GlExample::init()’:

main.cpp:78:54: error: ‘glViewport’ was not declared in this scope
         glViewport(0, 0, int(fbSize.x), int(fbSize.y));
                                                      ^
main.cpp:87:53: error: ‘glCreateShader’ was not declared in this scope
         vertShader = glCreateShader(GL_VERTEX_SHADER);
                                                     ^
main.cpp:88:59: error: ‘glShaderSource’ was not declared in this scope
         glShaderSource(vertShader, 1, &vertShaderSource, 0);
                                                           ^
main.cpp:89:35: error: ‘glCompileShader’ was not declared in this scope
         glCompileShader(vertShader);
                                   ^
main.cpp:90:61: error: ‘glGetShaderiv’ was not declared in this scope
         glGetShaderiv(vertShader, GL_COMPILE_STATUS, &status);
                                                             ^
main.cpp:93:64: error: ‘glGetShaderInfoLog’ was not declared in this scope
             glGetShaderInfoLog(vertShader, 512, 0, errorMessage);
                                                                ^
main.cpp:106:64: error: ‘glGetShaderInfoLog’ was not declared in this scope
             glGetShaderInfoLog(fragShader, 512, 0, errorMessage);
                                                                ^
main.cpp:113:36: error: ‘glCreateProgram’ was not declared in this scope
         program_ = glCreateProgram();
                                    ^
main.cpp:115:44: error: ‘glAttachShader’ was not declared in this scope
         glAttachShader(program_, vertShader);
                                            ^
main.cpp:117:31: error: ‘glLinkProgram’ was not declared in this scope
         glLinkProgram(program_);
                               ^
main.cpp:118:57: error: ‘glGetProgramiv’ was not declared in this scope
         glGetProgramiv(program_, GL_LINK_STATUS, &status);
                                                         ^
main.cpp:120:63: error: ‘glGetProgramInfoLog’ was not declared in this scope
             glGetProgramInfoLog(program_, 512, 0, errorMessage);
                                                               ^
main.cpp:125:34: error: ‘glDeleteShader’ was not declared in this scope
         glDeleteShader(vertShader);
                                  ^
main.cpp:129:65: error: ‘glGetUniformLocation’ was not declared in this scope
         uniformMVP_ = glGetUniformLocation(program_, "mvpMatrix");
                                                                 ^
main.cpp: In member function ‘virtual bool gl_ifi::GlExample::render()’:
main.cpp:137:31: error: ‘glEnable’ was not declared in this scope
         glEnable(GL_DEPTH_TEST);
                               ^
main.cpp:138:31: error: ‘glDisable’ was not declared in this scope
         glDisable(GL_CULL_FACE);
                               ^
main.cpp:141:44: error: ‘glClearColor’ was not declared in this scope
         glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
                                            ^
main.cpp:142:58: error: ‘glClear’ was not declared in this scope
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                                                          ^
main.cpp:145:30: error: ‘glUseProgram’ was not declared in this scope
         glUseProgram(program_);
                              ^
main.cpp:149:71: error: ‘glUniformMatrix4fv’ was not declared in this scope
     glUniformMatrix4fv(uniformMVP_, 1, GL_FALSE, &mvpMatrix_[0][0]);
                                                                   ^
main.cpp:151:52: error: ‘glBindVertexArray’ was not declared in this scope
         glBindVertexArray(cube_->getVertexArrayId());
                                                    ^
main.cpp:153:42: error: ‘glDrawElements’ was not declared in this scope
                        GL_UNSIGNED_INT, 0);
                                          ^
main.cpp: In member function ‘virtual bool gl_ifi::GlExample::end()’:
main.cpp:163:37: error: ‘glDeleteProgram’ was not declared in this scope
             glDeleteProgram(program_);
                                     ^
1
  • 2
    You didn't include the opengl header? Commented Feb 23, 2017 at 13:07

2 Answers 2

2

Not declared in scope means you didn't include the header, or didn't include it properly.

  #include <GL/glut.h>

Should give you everything. If that doesn't work, try just gl.h.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry I have forgot to mentioned this in my question, but I have tried this also. The output is simply the same. I am using Ubuntu 16.04, chances maybe my operating system fails at properly installing some components? I can't think of any other reason for this to not work!
Make sure the paths are set up correctly. Search for a file called gl.h, and it should be in an include directory somewhere. Then than include directory should be in you system paths as an include to search.
0

Those "glXXX was not declared" means you don't include glew.

Try something like #include "GLEW/include/GL/glew.h The idea is that glew.h must be included first.

Glew is used to find glXXX functions for OpenGL > 1.3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.