4

I have been scouring similar, existing Stack Overflow questions, but I am still clueless (this is my first time using cmake). I simply want to include headers that lie in subdirectories of /usr/include in my cmake project, but I obviously have no idea what I am doing :-) I am using the Bash shell and vim because I am cool like Mick Jagger.

Here is my CMakeLists.txt:

cmake_minimum_required (VERSION 2.8)

project (VoxelRPG)

set (VoxelRPG_VERSION_MAJOR 0)
set (VoxelRPG_VERSION_MINOR 1)

configure_file (
        "${PROJECT_SOURCE_DIR}/src/VoxelRPG.h.in"
        "${PROJECT_SOURCE_DIR}/src/VoxelRPG.h"
)

subdirs(src)

include_directories("/usr/include" "/usr/include/GL" "/usr/include/glm" "/usr/include/glm/gtc" "${PROJECT_SOURCE_DIR}/src")

set(HEADER_FILES "/usr/include/GL/glew.h" "/usr/include/GL/glfw.h" "/usr/include/glm/glm.hpp" "/usr/include/glm/gtc/matrix_transform.hpp")

add_executable(voxel_rpg src/main.cpp ${HEADER_FILES})

The CMakeLists.txt in the src directory is one line:

cmake_minimum_required (VERSION 2.8)

Here is the head of main.cpp (it shows the headers I want to use):

// Include GLEW
#include <GL/glew.h>

// Include GLFW
#include <GL/glfw.h>

// Include GLM
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
using namespace glm;

#include "shader.hpp"
#include "texture.hpp"

The cmake operation does not throw an error:

chris@stupid:~/voxel_rpg$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/chris/voxel_rpg

However, the make operation spits out this error message:

chris@stupid:~/voxel_rpg$ make
Linking CXX executable voxel_rpg
CMakeFiles/voxel_rpg.dir/src/main.cpp.o: In function `main':
main.cpp:(.text+0x16): undefined reference to `glfwInit'
main.cpp:(.text+0x62): undefined reference to `glfwOpenWindowHint'
main.cpp:(.text+0x76): undefined reference to `glfwOpenWindowHint'
main.cpp:(.text+0x8a): undefined reference to `glfwOpenWindowHint'
main.cpp:(.text+0x9e): undefined reference to `glfwOpenWindowHint'
main.cpp:(.text+0xea): undefined reference to `glfwOpenWindow'
main.cpp:(.text+0x11d): undefined reference to `glfwTerminate'
main.cpp:(.text+0x12d): undefined reference to `glewExperimental'
main.cpp:(.text+0x133): undefined reference to `glewInit'
main.cpp:(.text+0x177): undefined reference to `glfwSetWindowTitle'
main.cpp:(.text+0x183): undefined reference to `glfwEnable'
main.cpp:(.text+0x1ab): undefined reference to `glClearColor'
main.cpp:(.text+0x1b7): undefined reference to `glEnable'
main.cpp:(.text+0x1c3): undefined reference to `glDepthFunc'
main.cpp:(.text+0x1c8): undefined reference to `__glewGenVertexArrays'
main.cpp:(.text+0x1e0): undefined reference to `__glewBindVertexArray'
main.cpp:(.text+0x1ff): undefined reference to `LoadShaders(char const*, char const*)'
main.cpp:(.text+0x20a): undefined reference to `__glewGetUniformLocation'
main.cpp:(.text+0x408): undefined reference to `loadDDS(char const*)'
main.cpp:(.text+0x413): undefined reference to `__glewGetUniformLocation'
main.cpp:(.text+0x431): undefined reference to `__glewGenBuffers'
main.cpp:(.text+0x449): undefined reference to `__glewBindBuffer'
main.cpp:(.text+0x461): undefined reference to `__glewBufferData'
main.cpp:(.text+0x487): undefined reference to `__glewGenBuffers'
main.cpp:(.text+0x49f): undefined reference to `__glewBindBuffer'
main.cpp:(.text+0x4b7): undefined reference to `__glewBufferData'
main.cpp:(.text+0x4e4): undefined reference to `glClear'
main.cpp:(.text+0x4e9): undefined reference to `__glewUseProgram'
main.cpp:(.text+0x4fa): undefined reference to `__glewUniformMatrix4fv'
main.cpp:(.text+0x546): undefined reference to `__glewActiveTexture'
main.cpp:(.text+0x565): undefined reference to `glBindTexture'
main.cpp:(.text+0x56a): undefined reference to `__glewUniform1i'
main.cpp:(.text+0x582): undefined reference to `__glewEnableVertexAttribArray'
main.cpp:(.text+0x590): undefined reference to `__glewBindBuffer'
main.cpp:(.text+0x5a8): undefined reference to `__glewVertexAttribPointer'
main.cpp:(.text+0x5de): undefined reference to `__glewEnableVertexAttribArray'
main.cpp:(.text+0x5ec): undefined reference to `__glewBindBuffer'
main.cpp:(.text+0x604): undefined reference to `__glewVertexAttribPointer'
main.cpp:(.text+0x651): undefined reference to `glDrawArrays'
main.cpp:(.text+0x656): undefined reference to `__glewDisableVertexAttribArray'
main.cpp:(.text+0x664): undefined reference to `__glewDisableVertexAttribArray'
main.cpp:(.text+0x672): undefined reference to `glfwSwapBuffers'
main.cpp:(.text+0x67e): undefined reference to `glfwGetKey'
main.cpp:(.text+0x68f): undefined reference to `glfwGetWindowParam'
main.cpp:(.text+0x6ac): undefined reference to `__glewDeleteBuffers'
main.cpp:(.text+0x6c4): undefined reference to `__glewDeleteBuffers'
main.cpp:(.text+0x6dc): undefined reference to `__glewDeleteProgram'
main.cpp:(.text+0x6fd): undefined reference to `glDeleteTextures'
main.cpp:(.text+0x702): undefined reference to `__glewDeleteVertexArrays'
main.cpp:(.text+0x71a): undefined reference to `glfwTerminate'
collect2: error: ld returned 1 exit status
make[2]: *** [voxel_rpg] Error 1
make[1]: *** [CMakeFiles/voxel_rpg.dir/all] Error 2
make: *** [all] Error 2

Thanks in advance to the awesome people who help me!

3
  • 2
    You have linker error - you need to link gl library to your project - there's nothing wrong with header files. Commented Nov 21, 2013 at 19:42
  • You're right -- and since this is actually a question about linking, this question is a duplicate of another question (stackoverflow.com/questions/14077611/…). I am going to delete this question. Commented Nov 21, 2013 at 22:15
  • Actually all I could do was flag the question for deletion because it has an answer. Commented Nov 21, 2013 at 22:38

1 Answer 1

1

I think you want to use -L/usr/X11R6/lib -L/usr/local/lib -lGL -lGLU -lm -lglut to add the OpenGL libraries. Secondly, you don't need to add those sub-directories to your include_directories (or even '/usr/include' as gcc should be searching there by default).

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

1 Comment

I am having a problem in finding /usr/include/zlib.h even it is clearly there. Adding include_directories( /usr/include ) to CMakeLists.txt does not seem to help. There must be something else wrong. This only happens in my Docker file, but not in my regular machine. Anyone got a clue?

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.