I am trying to build an OpenGl application. First I used the old fixed function pipeline for drawing. Then I noticed that this is outdated and wanted to switch to the programmable pipeline. For this purpose I used some tutorials on the web. After changing my code I tried to compile it, but my compiler could not find the (core profile?) functions like glShaderSource, glCompileShader, glCreateProgram, glAttachShader, glLinkProgram and some more. I am not using the GLFW library for window managing or something similar but the xlib.
glxinfo | grep OpenGl is printing the following:
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 675M/PCIe/SSE2
OpenGL core profile version string: 4.3.0 NVIDIA 331.113
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.4.0 NVIDIA 331.113
OpenGL shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
I tried both the proprietary Nvidia driver and the open source driver but this did not fix the problem.
I include the OpenGl headers the following way:
#include <GL/gl.h>
#include <GL/glx.h>
Here is some of the compile error output:
In file included from main.cpp:1:0:
../../gui/iml/app.window.h: In constructor ‘gui::iml::AppWindow::AppWindow()’:
../../gui/iml/app.window.h:65:52: error: ‘glCreateShader’ was not declared in this scope
fragmentShader = glCreateShader(GL_VERTEX_SHADER);
^
../../gui/iml/app.window.h:66:47: error: ‘glShaderSource’ was not declared in this scope
glShaderSource(vertexShader,1,&vshader,NULL);
^
../../gui/iml/app.window.h:67:32: error: ‘glCompileShader’ was not declared in this scope
glCompileShader(vertexShader);
^
../../gui/iml/app.window.h:72:38: error: ‘glCreateProgram’ was not declared in this scope
GLuint sprogram = glCreateProgram();
^
../../gui/iml/app.window.h:73:50: error: ‘glAttachShader’ was not declared in this scope
glAttachShader(this->shaderProg,fragmentShader);
^
../../gui/iml/app.window.h:75:34: error: ‘glLinkProgram’ was not declared in this scope
glLinkProgram(this->shaderProg);
I compile the test program, I created for debugging, the following way:
g++ -Wall -Winline -DDEBUG main.cpp -I ../../gui/ -o debug -lX11 -lGL -lGLU -pthread -std=c++11
I think I have made a simple and stupid mistake but I don't get it...
edit: I looked into my gl.h file and it saw it is form the Mesa project:
/*
* Mesa 3-D graphics library
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
* Copyright (C) 2009 VMware, Inc. All Rights Reserved.
*
should this not be the header files of the Nvidia driver?
SOLVED:
I had to download the gl3.h header file from here: https://www.khronos.org/registry/gles/api/old/3.0/gl3.h and move it to /usr/include/GL/
Then I installed the OpenEs development files via:
sudo apt-get install libgles2-mesa-dev
and now the program compiles!
While your problem might be superficially go away you did actually not solve the root cause (at least not if you're aiming for LSB4 compliancy, out of sheer luck using just the glShader… functions your program actually complies with LSB5).
The problem you're running into is, that the Linux Standards Base (LSB) defines only OpenGL-1.2 as mandatory set of functions to be included into the system ABI. *Any symbol that goes beyond OpenGL-1.2 is not part of standard set of functions you are allowed to expect on a Linux Desktop system. Recently LSB5 was released which bumps the requirement to OpenGL-2.1.
Anyway, any function that's outside of what's defined in the LSB must (I repeat MUST) be resolved dynamically at runtime and tested for availability. If you don't do that your program will break on other people's systems eventually.
The relevant functions for resolving the symbols are
glXGetProcAddress
(orwglGetProcAddress
respectively on Windows). Do not enable prototype definition ofgl3.h
… only pain and suffering are down that road. Instead, to safe yourself the work, use a properly tested OpenGL loader library like GLEW (has its fair share of problems) or glLoadGen/glload (I recommend using the later).