I am trying to get an OpenGl project working on CLion. I am using 3 different libraries: GLEW, GLFW and SOIL.
The includes seem to work fine and everything get's found but every time I try to build I get errors:
undefined reference to `glfwInit'
undefined reference to `glfwWindowHint'
undefined reference to `glfwWindowHint'
undefined reference to `glfwWindowHint'
undefined reference to `glfwWindowHint'
undefined reference to `glfwCreateWindow'
...
C:/Users/John/OneDrive/OpenGL Projects/OpenGL/Lib_files/SOIL/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x3e): undefined reference to `glGetString@4'
C:/Users/John/OneDrive/OpenGL Projects/OpenGL/Lib_files/SOIL/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x72): undefined reference to `glGetString@4'
...
This is what I got in my cmake file:
cmake_minimum_required(VERSION 3.6)
project(OpenGL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp Shader.h Shader.cpp)
set(LIBS_DIR C:/Users/John/OneDrive/OpenGL\ Projects/OpenGL/Lib_files)
set(GLEW_ROOT_DIR ${LIBS_DIR}/GLEW )
set(GLFW_ROOT_DIR ${LIBS_DIR}/GLFW )
set(SOIL_ROOT_DIR ${LIBS_DIR}/SOIL )
set(GLEW_INCLUDE_DIRS ${GLEW_ROOT_DIR}/include)
set(GLFW_INCLUDE_DIRS ${GLFW_ROOT_DIR}/include)
set(SOIL_INCLUDE_DIRS ${SOIL_ROOT_DIR}/include)
set(GLEW_LIBRARY ${GLEW_ROOT_DIR}/lib/libglew32.a)
set(GLUT_LIBRARY ${GLFW_ROOT_DIR}/lib/libglfw3.a)
set(SOIL_LIBRARY ${SOIL_ROOT_DIR}/lib/libSOIL.a)
include_directories( ${GLEW_INCLUDE_DIRS} ${GLFW_INCLUDE_DIRS} ${SOIL_INCLUDE_DIRS})
add_executable(OpenGL ${SOURCE_FILES})
target_link_libraries(OpenGL libopengl32.a ${GLEW_LIBRARY} ${GLFW_LIBRARY} ${SOIL_LIBRARY})
Once I try to build I get a sea of "undefined reference" errors for GLFW and SOIL but not for GLEW.
What am I doing wrong?
GLUT_LIBRARYvariable to be pointed toglfwlibrary, but linking uses variableGLFW_LIBRARY. As for undefined references to GL functions in SOIL library: linking order has a sence. Library-consumer should come before library-provider intarget_link_librariescall. (There is definitely a question on SO which describes that, but I cannot find it.)