Why does g++ still require -latomic

纵饮孤独 提交于 2019-11-29 09:28:55

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!