Build Fails Using GCC-11 Due to Some Missing Standard Library Headers

845 Views Asked by At

After upgrading to gcc-11, which is shipped with Ubuntu 22.04, I started to get new compiler errors due to some missing Standard Library header files. Whereas previous gcc versions don't.

When I started to look into it, I learned from Porting to GCC 11 page, under the "Header dependency changes" section, that this is a new behavior due to some new specs in the standard itself.

Now, my question is: does the implementation of a particular C++ standard (i.e. C++17) change from one gcc version to another (i.e. gcc-9 and gcc-11)? I mean, how can the build fail if I'm building with different gcc versions but against the same C++ standard version (i.e. -std=c++17)?

And is that C++ Standard Library new requirement - of not to include other headers that were being used internally by the library - part of C++17 or C++20?

To get over this...
I manually included those header files where they were missing, and the build just succeeded. However, I was expecting behavior to be consistent when I build against a certain C++ version with different gcc versions. Or, am I missing something?

1

There are 1 best solutions below

0
Analytiker On

Thanks to JaMiT note, I realized that I got the note from GCC wrong. It's only their implementation of the Standard that got changed in GCC 11, and not the Standard itself.

When you thoroughly read the referenced section from that article, you can see that.

Header dependency changes

Some C++ Standard Library headers have been changed to no longer include other headers that were being used internally by the library. As such, C++ programs that used standard library components without including the right headers will no longer compile.

The following headers are used less widely in libstdc++ and may need to be included explicitly when compiled with GCC 11:

<limits>  (for std::numeric_limits)
<memory>  (for std::unique_ptr, std::shared_ptr etc.)
<utility> (for std::pair, std::tuple_size, std::index_sequence etc.)
<thread>  (for members of namespace std::this_thread.)