无法在CLion项目中包括SFML头文件 [英] Unable to include SFML header files in CLion project

查看:1189
本文介绍了无法在CLion项目中包括SFML头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对CMake和C ++一般都很新,所以今天我试图导入一个外部库像SFML到我的项目在Jetbrain的IDE CLION,但没有任何运气。



在花了一整天的时间了解了CMake,特别是使用SFML后,我最终管理了我的项目的CMake,找到了SFML库文件。 br>
然而,当我接近我自己的头文件包括一个SFML头,我遇到一个问题,因为它没有找到任何头从库 - 我的意思是#include指令。 br>
因为我是一个新手,我很迷失在这里。



这是我的CMakeLists.txt文件:

 #设置CMake的最小所需版本
cmake_minimum_required(VERSION 3.5)

设置(CMAKE_VERBOSE_MAKEFILE打开)

#set CMake的项目名称
项目(testproj)

include_directories($ {PROJECT_BINARY_DIR})

#Set CMake的标志
设置(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} -std = c ++ 11)

#设置源文件
设置(SOURCE_FILES Animal.cpp Animal.hpp ConstantValues.hpp Enums.hpp Mamal.hpp Mammals / Lion.cpp Mammals / Lion.hpp)
add_library(testproj SHARED $ { SOURCE_FILES})

#设置CMake的模块路径找到SFML Lib
设置(CMAKE_MODULE_PATH$ {CMAKE_SOURCE_DIR} / Modules /$ {CMAKE_MODULE_PATH})
设置(CMAKE_PREFIX_PATH $ {CMAKE_PREFIX_PATH}C:\\SFML\\SFML-2.3.2)

#查找SFML库
find_package(SFML 2 REQUIRED音频)
if(SFML_FOUND)
include_directories($ {SFML_INCLUDE_DIR})
target_link_libraries(testproj $ {SFML_LIBRARIES})
endif(SFML_FOUND)

值得注意的是,我在Windows上工作,我只查看SFML中的音频模块。

我缺少什么? p>

解决方案

OK所以我设法拉到这个谢谢@ Tsyvarev的帮助。
当我意识到问题只与#include指令相关,而不是CMake脚本,我对它进行了更深入的研究,发现与SFML的官方文档相反,每个模块的头文件位于在其匹配目录下



因此,例如要包含音频模块的头文件,我应该这样做:

  #include  

这里的关键是首先查看SFML文件夹,就像使用boost一样。 / p>

I'm quite new to CMake and C++ in general, so today I've tried to import an external library like SFML to my project in Jetbrain's IDE CLion, but without any luck.

After spending a whole day learning about CMake in general and making SFML work with CMake in particular, I've finally managed my project's CMake to find the SFML library files.
However, when I approached a header file of my own to include a SFML header, I encountered a problem as it didn't find any headers from the library - And by that I mean the #include directives.
Since I am a newbie, I'm quite lost here.

Here's my CMakeLists.txt file:

# Set CMake's minimum required version
cmake_minimum_required(VERSION 3.5)

set(CMAKE_VERBOSE_MAKEFILE on)

#Set CMake's project name
project(testproj)

include_directories("${PROJECT_BINARY_DIR}")

#Set CMake's flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

#Set source files
set(SOURCE_FILES Animal.cpp Animal.hpp ConstantValues.hpp Enums.hpp Mamal.hpp Mammals/Lion.cpp Mammals/Lion.hpp)
add_library(testproj SHARED ${SOURCE_FILES})

#Set CMake's module path to find the SFML Lib
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Modules/" ${CMAKE_MODULE_PATH})
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:\\SFML\\SFML-2.3.2")

#Find the SFML lib
find_package(SFML 2 REQUIRED audio)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(testproj ${SFML_LIBRARIES})
endif (SFML_FOUND)

It is worth noting that I'm working on Windows and I look only for the audio module in SFML.
What am I missing?

解决方案

OK So I've managed to pull to this off thanks to @Tsyvarev's help. When I realized that the problem is related only to the #include directives and not the CMake script, I took a bit deeper look in it and found out that opposed to SFML's official documentation, the header files for each module are located under their matching directory.

So for example to include a header file from the audio module, I should do this:

#include <SFML/Audio/sound.hpp>

The key here is to look in the SFML folder first, just as you would do with boost.

这篇关于无法在CLion项目中包括SFML头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆