How to Solve Fatal error stdatomic in C/C++ Compilation

Fatal error: stdatomic. H: no such file or directory

Under Linux, errors are reported when compiling the source code using gcc

fatal error: stdatomic.h: No such file or directory
 #include <stdatomic.h>
compilation terminated.

The reason is that the version of GCC 4.8 is too low and requires a higher version of GCC. How to safely upgrade the GCC version?

The devtoolset package can be installed through CentOS release SCL source

yum install centos-release-scl
yum install devtoolset-8

Or add your own source to install it (I’ll take centos7 as an example)

vi /etc/yum.repos.d/CentOS-SCLo-scl.repo
name=CentOS-7 - SCLo sclo

Activate the GCC version to make it effective

scl enable devtoolset-8 bash


source /opt/rh/devtoolset-8/enable

At this time, you can see through the GCC — version command that the GCC version has changed to 8.X.x. it is worth noting that this only takes effect in the current bash. If it needs to take effect permanently, you can add environment variables yourself.

Read More: