-1

I've seen several questions discussing this topic but none of their solutions seems to apply here. I have several libraries that I don't wont to be compiled every time I build the project so I've created "b5pch.h" and b5pch.cpp" files.

//b5pch.h
#pragma once

#include <iostream>
#include <memory>
#include <utility>
#include <algorithm>
#include <functional>

#include <sstream>
#include <string>
#include <vector>

#ifdef B5_PLATFORM_WINDOWS
    #include <Windows.h>
#endif
//b5pch.cpp
#include "b5pch.h"

In properties I've set precompiled header for every cpp file to be Use(/Yu) like so:enter image description here

And for b5pch.cpp it's set to Create(/Yc)

after that I've added #include "b5pch.h at the start of each cpp file(I only have two not including b5pch.cpp) but when I try to build the project I get two errors saying exactly the same thing

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

enter image description here

Boss
  • 21
  • 6
  • You need to `#include "b5pch.h"` in the source files where you need that set of headers and build with the same options. I'd suggest the `b5pch.cpp` file isn't needed, but up to you. If all you're doing in your header is including standard headers or Microsoft headers, there's a good chance that you won't gain much using precompiled headers anyway. Incidentally, going out of your way to use precompiled headers before you have evidence of need (e.g. long build times, and evidence that precompiled headers can mitigate that) you're probably doing premature optimisation. – Peter May 09 '21 at 00:18
  • Your configuration looks correct, even though you only showed half of it. It is important the preprocessor macros for each file are also consistent, and above all, consistent with the preprocessor defines for the pch builder file if you're using a create+use strategy (and you are). I'd check there as well. When I do this I do it pretty much the same as you: global "Use" and specify the pch header, then the single pch cpp file is changed to "Create", specifying the pch header as the "through" ingest. – WhozCraig May 09 '21 at 00:30

1 Answers1

1

Okay I've fixed the problem. when I was including b5pch.h in my cpp files I was doing it like this: #include ../b5pch.h since they were in different directories. When I moved pch files in same directory and I just wrote #include b5pch.h there were no more errors. I didn't wanted them to be in same folder so I've moved them back out but in Project Properties->Additional Include Directories I've added "src" so I could just use #include b5pch.h in my cpp files even tho they were not in the same folder.

Boss
  • 21
  • 6