Unable to include SFML header files in CLion project

蓝咒 提交于 2019-12-26 01:31:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/38809049/unable-to-include-sfml-header-files-in-clion-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!