0
votes

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
@RichardCritten Every .cpp file starts with the appropriate relative version of #include "pch.h"user7898257
When precompiled headers are enabled every source file should have #include "pch.h" as the first non empty non comment linedrescherjm
@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
"... relative..." that's the problem the directive does not match the #includeRichard Critten

1 Answers

0
votes

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!