Why does g++ still require -latomic

后端 未结 3 635
粉色の甜心
粉色の甜心 2020-12-18 22:00

In 29.5 Atomic types of the C++ Standard November 2014 working draft it states:

  1. There is a generic class template atomic. The type of
相关标签:
3条回答
  • 2020-12-18 22:36

    g++ is a wrapper for gcc which adds the correct C++ libraries. Clearly -latomic is missing from that list. Not a core compiler problem then, simply a minor bug in the wrapper.

    0 讨论(0)
  • 2020-12-18 22:39

    I know that the standard doesn't say anything about compiler flags or libraries that have to be included

    Right.

    but so far I thought that any standard conformant, single file code can be compiled via the first command.

    Well, no. As you just said, there is no particular reason to assume this. Consider also that GCC extensions are enabled by default.

    That being said, it seems self-evident that the intention is to make -latomic a default part of the runtime when it's settled down a bit.

    0 讨论(0)
  • 2020-12-18 22:47

    Relevant reading on the GCC homepage on how and why GCC makes library calls in certain cases regarding <atomic> in the first place.

    GCC and libstdc++ are only losely coupled. libatomic is the domain of the library, not the compiler -- and you can use GCC with a different library (which might provide the necessary definitions for <atomic> in its main proper, or under a different name), so GCC cannot just assume -latomic.

    Also:

    GCC 4.7 does not include a library implementation as the API has not been firmly established.

    The same page claims that GCC 4.8 shall provide such a library implementation, but plans are the first victims of war. I'd guess the reason for -latomic still being necessary can be found in that vicinity.

    Besides...

    ...so far I thought that any standard conformant, single file code can be compiled via the first command.

    ...-lm has been around for quite some time if you're using math functions.

    0 讨论(0)
提交回复
热议问题