我有一个 CMake 使用 SFML 库生成的 VS2010 项目。项目是这样设置的,将lib/SFML-2.0-rc/include添加到包含目录中:
/lib
+ /SFML-2.0-rc
+ /include
+ /SFML
+ Graphics.hpp
+ /lib
/project
+ /src
+ /engine
+ /assets
+ CMakeLists.txt
+ asset.hpp
+ CMakeLists.txt
+ engine.hpp
+ engine.cpp
+ CMakeLists.txt
+ main.cpp
+ CMakeLists.txt
我正在尝试使用#include <SFML/Graphics.hpp>
assets.hpp ,但出现以下错误:
fatal error C1083: Cannot open include file: 'SFML/Graphics.hpp': No such file or directory
尝试从engine.hpp中包含时,我也会收到该错误。但是,在engine.cpp中,我已经在使用该包含行,并且可以成功构建和运行该项目。
Visual Studio 能够自动完成 SFML 包含路径,并且在Configuration Properties > C/C++ > Additional Include Directories我可以看到所有库都已配置。
所以我的问题是:什么可能导致此错误仅在包含头文件时发生?
CMakeLists 文件
这些是生成 VS2010 解决方案的 CMake 构建文件。
项目/CMakeLists.txt
cmake_minimum_required (VERSION 2.8)
project (project)
set (project_SOURCE
""
)
include_directories("src")
add_subdirectory (src)
add_executable (project ${project_SOURCE})
target_link_libraries (project Engine)
项目/src/CMakeLists.txt
set (project_SOURCE
${project_SOURCE}
"${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
PARENT_SCOPE
)
include_directories ("engine")
add_subdirectory (engine)
项目/src/engine/CMakeLists.txt
set (HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/engine.hpp"
)
set (SOURCE
"${CMAKE_CURRENT_SOURCE_DIR}/engine.cpp"
)
include_directories("assets")
add_subdirectory(assets)
add_library(Engine
${SOURCE} ${HEADERS}
)
set (LIBS_ROOT "" CACHE PATH "Root directory of external libs")
set (LIBS_SFML_FOLDER "SFML-2.0-rc" CACHE STRING "Name of the SFML external folder")
set (SFMLDIR "${LIBS_ROOT}/${LIBS_SFML_FOLDER}")
## SFML
if (NOT SFMLDIR)
message (FATAL_ERROR "SFML directory hasn't been specified")
endif()
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${SFMLDIR}/cmake/Modules")
set (SFML_STATIC_LIBRARIES TRUE)
set (SFML_COMPONENTS system window graphics network audio main)
find_package (SFML 2 COMPONENTS ${SFML_COMPONENTS} REQUIRED)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries (Engine ${SFML_LIBRARIES})
endif ()
项目/src/engine/assets/CMakeLists.txt
set (HEADERS
${HEADERS}
"${CMAKE_CURRENT_SOURCE_DIR}/asset.hpp"
PARENT_SCOPE
)