如何在我的cmake项目中包含来自/ usr / include的头文件?

时间:2013-11-21 19:39:03

标签: c++ cmake

我一直在搜索类似的,现有的Stack Overflow问题,但我仍然无能为力(这是我第一次使用cmake)。我只想在我的cmake项目中包含位于/ usr / include子目录中的标题,但我显然不知道我在做什么:-)我正在使用Bash shell和vim,因为我很酷,像Mick Jagger。

这是我的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})

src目录中的CMakeLists.txt是一行:

cmake_minimum_required (VERSION 2.8)

这是main.cpp的头部(它显示了我想要使用的标题):

// 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"

cmake操作不会抛出错误:

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

但是,make操作会吐出此错误消息:

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

提前感谢那些帮助我的人!

1 个答案:

答案 0 :(得分:1)

我认为您希望使用-L/usr/X11R6/lib -L/usr/local/lib -lGL -lGLU -lm -lglut添加OpenGL库。其次,您不需要将这些子目录添加到include_directories(甚至是'/ usr / include',因为默认情况下gcc应该在那里搜索)。