user18490
user18490

Reputation: 3839

C++ code using GLFW3 on Maverick: glShaderSource no matching function

I am trying to compile a fairly simple C++ program using the library GLFW3 on Mac. The OS is OS 10.9.3 (Maverick). It compiles fine until I try to use GLSL functions such as glShaderSource, etc.

Here are the include files I use:

#include <GLFW/glfw3.h>
#include <cstdlib>
#include <cstdio>

I am using OpenGL3.2:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

Here is the command line to compile the program:

clang++ -o xxxx xxxx.cpp  -framework Cocoa -framework OpenGL  -Wall -lglfw3 -I/usr/local/include/ -L/usr/local/lib  -framework Quartz -framework IOKit

And now the error:

xxxx:38:5: error: no matching function for call to 'glShaderSource'
    glShaderSource(vertexShader, 1, &vertexSource, NULL);

I am sure I missing something basic but what? Thanks for your help. I fear it has something to do with glext but not sure what to do really. I couldn't find anything on Stackoverflow on the web.

Upvotes: 0

Views: 833

Answers (1)

Reto Koradi
Reto Koradi

Reputation: 54642

On OS X, you need to include <OpenGL/gl3.h> to get definitions for GL3+ level entry points.

In the GLFW documentation, on the page "Building programs that use GLFX" (http://www.glfw.org/docs/latest/build.html), there is a section named "GLFW header option macros". The relevant sections are:

These macros may be defined before the inclusion of the GLFW header and affect the behavior of the header.

GLFW_INCLUDE_GLCOREARB makes the header include the modern GL/glcorearb.h header (OpenGL/gl3.h on OS X) instead of the regular OpenGL header.

So the following should do the trick:

#define GLFW_INCLUDE_GLCOREARB
#include <GLFW/glfw3.h>

Looking at the glfw3.h header (http://www.glfw.org/docs/latest/glfw3_8h_source.html) confirms that it will include <OpenGL/gl3.h> with this additional define.

Upvotes: 2

Related Questions