Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat would cause VS2010 to fail to include from header files, but not from implementation files?
    text
    copied!<p>I have a VS2010 project that's being generated by CMake, using the SFML library. The project is set up like so, with <em>lib/SFML-2.0-rc/include</em> added to the include directories:</p> <pre><code>/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 </code></pre> <p>I am trying to use <code>#include &lt;SFML/Graphics.hpp&gt;</code> from <em>assets.hpp</em>, but I get the following error:</p> <pre><code>fatal error C1083: Cannot open include file: 'SFML/Graphics.hpp': No such file or directory </code></pre> <p>I also get that error when trying to include from <em>engine.hpp</em>. However, in <em>engine.cpp</em> I was already using that include line, and I could build and run the project successfully.</p> <p>Visual Studio is able to auto-complete the SFML include paths, and in <em>Configuration Properties > C/C++ > Additional Include Directories</em> I can see all of the libraries are configured.</p> <p>So my question is this: <strong>what could cause this error to only happen when including from a header file?</strong></p> <h1>CMakeLists files</h1> <p>These are the CMake build files that generated the VS2010 solution.</p> <h3>project/CMakeLists.txt</h3> <pre><code>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) </code></pre> <h3>project/src/CMakeLists.txt</h3> <pre><code>set (project_SOURCE ${project_SOURCE} "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" PARENT_SCOPE ) include_directories ("engine") add_subdirectory (engine) </code></pre> <h3>project/src/engine/CMakeLists.txt</h3> <pre><code>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 () </code></pre> <h3>project/src/engine/assets/CMakeLists.txt</h3> <pre><code>set (HEADERS ${HEADERS} "${CMAKE_CURRENT_SOURCE_DIR}/asset.hpp" PARENT_SCOPE ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload