0

I've been trying to organize my code into sub-folders, and I've been careful to not do anything extra than that since my last commit. I am currently getting a bunch of C1010 errors saying:

unexpected end of file while looking for precompiled header. Did you forget to add #include "pch.h" to your source?

Each file does have the appropriate relative include path for the precompiled header file. If I attempt to "de-relativize" the precompiled header includes, then Intellisense starts throwing errors..

I suspect that my cmake code might be at fault here.. Specifically this section:...

if (MSVC)
    set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Minecraft)

    set_target_properties(Minecraft PROPERTIES COMPILE_FLAGS "/Yupch.h")
    set_source_files_properties("src/pch.cpp" PROPERTIES COMPILE_FLAGS "/Ycpch.h")

    target_compile_options(Minecraft PRIVATE "/W4" "/MP" "/std:c++17")
endif()
  • 1
    Does every `*.cpp` file start with `#include "pch.h"` ? – Richard Critten Feb 18 '21 at 18:35
  • @RichardCritten Every `.cpp` file starts with the appropriate _relative_ version of `#include "pch.h"` –  Feb 18 '21 at 18:36
  • When precompiled headers are enabled every source file should have `#include "pch.h"` as the first non empty non comment line – drescherjm Feb 18 '21 at 18:36
  • @ConnorMoody Ever file mentioned in the screen shot (please post error messages as text) does not have the `#include` the path must match the name in the compiler directive, i don't think relative paths will work. – Richard Critten Feb 18 '21 at 18:37
  • Maybe Intellisense is confused with this: ***file starts with the appropriate relative version*** – drescherjm Feb 18 '21 at 18:38
  • Why not use cmake's [target_precompile_headers](https://cmake.org/cmake/help/git-stage/command/target_precompile_headers.html) instead of trying to roll your own? – spectras Feb 18 '21 at 18:38
  • @RichardCritten That is what the error messages suggest, but that is not the case. Each `.cpp` file indeed starts immediately with the appropriate relative version of `#include "pch.h"` –  Feb 18 '21 at 18:39
  • @spectras I suppose that is an option, I would have to learn how to implement that, but technically speaking this should be able to work regardless. –  Feb 18 '21 at 18:40
  • 1
    _"... relative..."_ that's the problem the directive does not match the #include – Richard Critten Feb 18 '21 at 18:40
  • I always add the include directories via CMake and just use `#include "pch.h"` – drescherjm Feb 18 '21 at 18:40
  • @RichardCritten Intellisense appears to throw errors if I "de-relativize" the `pch.h` includes though? –  Feb 18 '21 at 18:41

1 Answers1

0

So replacing the following code...

if (MSVC)
    set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Minecraft)

    set_target_properties(Minecraft PROPERTIES COMPILE_FLAGS "/Yupch.h")
    set_source_files_properties("src/pch.cpp" PROPERTIES COMPILE_FLAGS "/Ycpch.h")

    target_compile_options(Minecraft PRIVATE "/W4" "/MP" "/std:c++17")
endif()

with

if (MSVC)
    set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Minecraft)

    target_precompile_headers(Minecraft PRIVATE "src/pch.h")

    target_compile_options(Minecraft PRIVATE "/W4" "/MP" "/std:c++17")
endif()

solved the issue!