0

EDIT: This seems to be a GCC issue

The error is this:

mingw32-make[2]: *** [CMakeFiles\MyProject.dir\build.make:94: CMakeFiles/MyProject.dir/main.cpp.obj] Error 1

Line 94 in build.make looks like this:

C:\PROGRA~1\mingw64\bin\G__~1.EXE $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -Winvalid-pch -include MyProjectDirectory/build/CMakeFiles/MyProject.dir/cmake_pch.hxx -MD -MT CMakeFiles/MyProject.dir/main.cpp.obj -MF CMakeFiles\MyProject.dir\main.cpp.obj.d -o CMakeFiles\MyProject.dir\main.cpp.obj -c MyProjectDirectory\main.cpp

It appears when I try to build a project that includes certain sets of files in the precompiled header.

Through trial and error I have found two sets of includes that cause this error. The first is the single file vulkan.hpp from the Vulkan SDK. The second is the three files SDL.h from SDL, VkBootstrap.h from the Vulkan Bootstrapping Library, and "filesystem" from the standard library. I'm using GCC with MinGW-w64. If I remove any of the three includes, the error does not appear.

I've tried making a simple project with just the precompiled header and an empty main(). I have no idea what's causing this, and I would prefer not having to dig through these files manually.

Here's a minimal reproducible example:

All files are in the same directory. The directory also contains the folder named "vulkan" from the "include" folder in the Vulkan headers.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(MyProject VERSION 0.1.0)

add_executable(${PROJECT_NAME} main.cpp)

target_include_directories(${PROJECT_NAME}
    PUBLIC .
)

target_precompile_headers(${PROJECT_NAME}
    PRIVATE pch.hpp
)

main.cpp:

int main()
{
    return 0;
}

pch.hpp:

#pragma once

#include "vulkan/vulkan.hpp"
VV65536
  • 11
  • 2
  • "_If I remove any of the three files_" did you mean "If I don't `#include` any of the three files"? Or do you mean actually removing (deleting) those files from your filesystem? – starball Mar 06 '23 at 19:55
  • I mean "If I don't `#include` any of the three files". I changed it to be more clear. – VV65536 Mar 07 '23 at 04:59
  • By passing additional option `VERBOSE=1` to `mingw32-make` you could see the exact command lines which are executed (with variables like `CXX_DEFINES` being expanded). You could run the failed command line as "standalone" and check its output. – Tsyvarev Mar 07 '23 at 08:04
  • @Tsyvarev I did that and ran the command. It exited with code 1, but it didn't print anything, even with `-Wall -Wextra`. I then tried compiling a simple file with an error, which it printed. Could there be a problem with the compiler, or is this normal? I tried googling for this, but I didn't find anything. – VV65536 Mar 07 '23 at 17:04
  • "Could there be a problem with the compiler, or is this normal?" - I am not an expert in precompile headers, but a compiler returning non-zero with no message doesn't look as correct one. – Tsyvarev Mar 07 '23 at 18:26
  • Looks like such behavior of gcc with precompiled headers is not new: https://stackoverflow.com/questions/30081112/gcc-fails-with-no-message-when-using-precompiled-headers. CMake is definitely not responsible for it. – Tsyvarev Mar 07 '23 at 18:40

0 Answers0