cmake链接提示头文件

cmake链接提示头文件

本文介绍了cmake链接提示头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CMake(v 3.10.1)将外部库添加到我的项目中

I'm trying to add an external library to my project using CMake (v 3.10.1)

我希望这些库位于一个特定的目录中,因为我希望保持它们的整洁

I want the libs to live in a specific directory because I like to keep it as clean as possible

我的项目结构如下

Project
   |
   |-- main.cpp
   |-- CMakeLists.txt (top lvl)
   |
   |-- libs/
         |
         | -- glew-1.13.0
         | -- CMakeLists.txt (lib lvl)

顶部lvl CMakeLists.txt

Top lvl CMakeLists.txt

cmake_minimum_required (VERSION 2.6)
project (myproject)
add_executable(myproject main.cpp)

add_subdirectory (libs)

库lvl CMakeList.txt

Lib lvl CMakeList.txt

### GLEW ###

include_directories(
    glew-1.13.0/include/
)

set(GLEW_SOURCE
    glew-1.13.0/src/glew.c
)

set(GLEW_HEADERS
)

add_library( GLEW_1130 STATIC
    ${GLEW_SOURCE}
    ${GLEW_INCLUDE}
)

target_link_libraries(GLEW_1130
  ${OPENGL_LIBRARY}
  ${EXTRA_LIBS}
)

main.cpp

#include <iostream>
#include <GL/glew.h>


int main() {

    std::cout << "Hello World" << std::endl;
    return 0;
}

<GL/glew.h> headerfile not found

在我的情况下,我缺少什么以便可以使用glew头文件?

What am I' missing in my case so that I can use the glew header files?

推荐答案

include_directories的效果不全局:从libs/CMakeLists.txt执行,对 top无效级 CMakeLists.txt.

Effect of include_directories is not global: being performed from libs/CMakeLists.txt, it doesn't affect on top-level CMakeLists.txt.

您可以将包含目录附加"到库 target :

You may "attach" include directories to the library target:

# In libs/CMakeLists.txt
target_include_directories(GLEW_1130 PUBLIC glew-1.13.0/include/)

因此进一步将该库作为 target 链接:

so futher linking with that library as target:

# In CMakeLists.txt
target_link_libraries(myproject GLEW_1130)

将自动将其包含目录传播到可执行文件.

will automatically propagate its include directories to the executable.

这篇关于cmake链接提示头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 01:33