Undefined reference to `glActiveTexture' CMAKE

Hello! I am having this compiler error “undefined reference to glActiveTexture” and I have no idea why this is happening. I should start of with saying that I am new to opengl, but it appears that every other function I have tried works just fine, I have been able to create a context and draw multiple images using functions such as “SDL_GL_CreateContext”, “glBindTexture”, “glTexCoord2f” etc.

these are my includes:

#include <GL/gl.h>
#include <GL/glext.h>

My CMakeLists.txt looks pretty much like this:

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_CXX_FLAGS "-DGL_GLEXT_PROTOTYPES -std=c++11")


set(SDL2_INC_DIR "C:/SDL2_64/include")
set(SDL2_LIB_DIR "-LC:/SDL2_64/lib")
set(SDL2_LIBS "-lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer")

set(GL_LIBS "-lglu32 -lopengl32")

include_directories(.)
include_directories(src)

include_directories(untitled ${GL_INC_DIR} ${SDL2_INC_DIR})

target_link_libraries(untitled  -lmingw32 ${SDL2_LIBS} ${SDL2_LIB_DIR} ${GL_LIBS})

Any ideas?

Sounds like you’re on Windows.

You need to either:

  1. use a GL function loader library like GLEW or GLAD, or
  2. pull in the function pointers yourself using wglGetProcAddress().

#1 is very easy.

See:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.