2

I'm working on a project using libraries handled through vcpkg. As compile time wasn't that great, I did some headers clean up and configured the project to use precompiled headers, putting STL and vcpkg headers inside.

I started to run into the infamous C1076, C3859 and C1060 errors, and a quick check to the generated pch showed me a massive 1.2GB file ...

I ran a build using the /showIncludes switch, and it appears that spirit-po, a Boost based library that I use for translations, references more than 2600 Boost headers. (My project just has 70 files, with nothing fancy) It's the only Boost based library used in the project.

Just to be sure this was the culprit, I removed everything but the spirit-po files from the pch :

#pragma warning(push)
#pragma warning(disable : 4267)
#include <spirit_po/spirit_po.hpp>
#pragma warning(pop)

and the resulting generated file is still 1GB big ...
There's no difference in size between debug and release build.
With an empty pch file, the generated file is around 4MB.

Provided that a 250MB file is considered big, how come I end up with a file 4 times that size ?

With just that library in the pch I don't have errors compiling anymore, but I don't want the problem to arise again in the future.

I'm using Microsoft Visual Studio Community 2019 Version 16.8.4.

What are my options to improve the situation ?
Could this be a misconfiguration in Visual Studio ?
Do I have to ditch the library altogether to remove the Boost dependency ?
Is there another alternative ?

Thanks for reading me :)

Runik
  • 155
  • 1
  • 9
  • Unfortunately, your "options to improve the situation" are rather slim. It is what it is. There are no alternatives. If something includes a bunch of header files, and you want to precompile and save them, then that's what you get. Nobody is going to tell you to "ditch the library altogether", that's your decision to make, if you wish. – Sam Varshavchik Jan 16 '21 at 15:03

2 Answers2

2
  1. Header only libraries work because there are no details left out of those headers.

  2. Precompiled headers contain all the compiled information of the headers before start of the translation unit.

  3. A large part (the majority) of boost libraries are header only. To add insult to injury, they're highly generic meaning there will be many templates and their instantiations.

1 + 2 + 3 are the perfect storm. If the size is a concern, your better bet is to shield boost from your headers and include them in the select translation units that actively depend on them.

sehe
  • 374,641
  • 47
  • 450
  • 633
1

While doing some more research, I came across the following libraries :

  • tinygettext :
    + Doesn't depend on Boost
    - Needs Iconv library to work, which isn't that trivial to make it work on Windows even if it's available as a vcpkg package
  • spiritless_po
    + Doesn't depend on Boost
    + Self contained
    - Not compatible with spirit-po

I tested both, and I must say the last one is a perfect fit for my use, which is to use directly po files as translations ... I guess it's not a fit all solution, but it might be enough for some.

Runik
  • 155
  • 1
  • 9
  • Oh. You didn't ask for alternatives (neither did you say you were /only/ using spirit-po). (If you had, that [would not have been a good fit for SO (ad. 4)](https://stackoverflow.com/help/on-topic)). Also, I think you missed the obvious approaches: disable PCH or switch to a compiler that handles them better. All that said, I would never introduce Boost for gettext. Gettext's elegance comes from it being so bare-bones/lightweight (and slightly archaic, but that proves its use). – sehe Jan 18 '21 at 13:04
  • Stilll the question is "Why is my generated precompiled file so big when using a boost based library?". Anywhich way you turn it makes it not a good fit for SO. Asking several questions at once isn't encouraged, nor is asking for library recommendations. Anyhow, you found a good soltuion, so cheers! I was merely trying to improve your future experience on the site. – sehe Jan 18 '21 at 13:42
  • Sorry, I saved my answer too soon ... @sehe I actually said both if you check my question, but I guess formulation wasn't that good, as you didn't notice it. My original question was still to understand why the precompiled header was so big, and I found the alternatives while trying to fix it. That project used various Boost libraries in the beginning, but as some were integrated in the STL I switched to these and spirit-po was the only one left. That's all of it ... and now I'm free of any Boost dependency :) – Runik Jan 18 '21 at 13:48
  • 1
    @sehe Thanks for your advices, I'm not fully accustomed yet on how things work aroud here – Runik Jan 18 '21 at 13:51