I've just compiled GCC 4.7 to work with stdatomic.h
, but I can't seem to -I
it. stdatomic.h
seems to live in /usr/include/c++/4.4.3
, but then the linker tells me it needs a bunch of other files in dirs nearby. If I -I
all of them, I still get the error undefined reference to atomic_flag_clear_explicit
. Any ideas how I'm supposed to link this right?

- 90,663
- 31
- 146
- 203

- 19,515
- 28
- 127
- 217
-
Didn't the 4.7 source package come with a 4.7 libstdc++ as well? – Mar 29 '12 at 02:18
-
Oh, I see, you mean I may be linking to the wrong include? Let me see. – Dervin Thunk Mar 29 '12 at 02:21
-
@K.G. `
` is standard C, not C++. – Some programmer dude Mar 29 '12 at 05:43 -
Are you sure you get the correct compiler? Try `gcc --version` to see what version you are using. You might want to use `gcc-4.7` instead to make sure you get the correct compiler, which will have all correct paths built in. – Some programmer dude Mar 29 '12 at 05:45
-
@JoachimPileborg: Yes, I compiled it with "--program-suffix=-4.7", so it is calling the right version. – Dervin Thunk Mar 29 '12 at 10:27
-
I still can't do this. Any ideas? – Dervin Thunk Mar 29 '12 at 19:49
-
Clearly your gcc installation is borked – Gunther Piez Mar 29 '12 at 20:55
3 Answers
The <stdatomic.h> header in GCC 4.4 and 4.5 was from an early draft of C++0x atomics, but is not part of the final standard, so it was removed from libstdc++.
The C++ compiler supports C++11 atomics via the C++11 <atomic> header, so you should use that header in C++ code.
When the C compiler supports C11 atomics, the <stdatomic.h> header will be provided again.

- 383
- 3
- 6
First, if you are compiling with GCC 4.7 you should not be including or linking anything from a directory from GCC 4.4.
Second, -I
only affects the search path for header files. "undefined reference" is a linker error and usually means it hasn't found the right library. You change the library search path with -L
. The linker didn't say it didn't find a library with the right name, it says it didn't find a symbol, so clearly the library it did find didn't have that symbol. I'd suggest you have a versioning problem, perhaps caused by a installation problem.

- 24,923
- 4
- 54
- 75
Using this command solved the problem for me:
$ scl enable devtoolset-7 bash
I got the same error as you when entering sudo make altinstall
for installing Python 3.8.5 on CentOS 7.

- 34,860
- 64
- 239
- 408