2

I have an eclipse c++ project that uses some c++11 features. It uses cmake for building so it is setup in eclipse as a project with existing makefiles.

It builds fine with the makefiles either in eclipse or from the command line. But I get syntax errors with atomic_bool saying the symbol can't be resolved. I have added -std=c++11 under 'C/C++ General -> Preprocessor Include Pattern -> Providers -> CDT GCC Built-in Compiler Settings' and I have the toolchain in eclipse set to MacOSX GCC.

Note: other c++11 things like thread or shared_ptr don't give any syntax errors.

The errors come from the <atomic> header where there is the preprocessor if statement

#if !__has_feature(cxx_atomic)
#error <atomic> is not implemented
#else
...

Everything below the #else is grayed out. So apparently __has_feature(cxx_atomic) evaluates to 0 according to eclipse. But if I check it from the command line it shows that it should evaluate to true.

$ echo '__has_feature(cxx_atomic)' | g++ -x c++ -std=c++11 -E -
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 188 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
1

Why does __has_feature(cxx_atomic) evaluate to false in Eclipse but not if I check the compiler itself?

Sean Lynch
  • 2,852
  • 4
  • 32
  • 46
  • possible duplicate of [Eclipse CDT C++11/C++0x support](http://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support) – Praetorian Mar 26 '14 at 23:06
  • @Praetorian This is not a duplicate. The `-std=c++0x` and `__GXX_EXPERIMENTAL_CXX0X__` was a hack from the early days of C++11 support. The [second answer](http://stackoverflow.com/a/13549029/1046297) mentions the process that I followed. In my case all of C++11 that I've tried works fine except for atomic. So this is a different question. – Sean Lynch Mar 27 '14 at 01:00
  • @Sean Lynch - I don't have an answer to your question... But why would one prefer CLang to GCC? I'm definitely curious. Thank you in advance! – FoggyDay Mar 28 '14 at 02:00
  • @FoggyDay I actually don't prefer it. But I'm stuck with OS X right now and I feel like everything works more smoothly when you use what they want you to use on their platform. They definitely don't care about gcc and I've run into subtle annoyances when using gcc on OS X. – Sean Lynch Mar 28 '14 at 02:09
  • OK, thank you. You're using CLang because you're on a Mac. But I'm still confused - why are you using Eclipse instead of XCode? Again - I don't know. I'm just curious... – FoggyDay Mar 28 '14 at 02:38
  • @FoggyDay I did try XCode. I tried to get used to it but I really didn't like that it's so specific to developing cocoa applications. I had some issues with it that I can't remember now although I'm pretty sure they were minor. But I just didn't like it. All in all my opinion is that developing anything other than cocoa applications on OS X pretty much sucks compared to Linux but as I said, I'm stuck with it for now. Eclipse with clang seems to be the best case senario IMHO. – Sean Lynch Mar 28 '14 at 11:20
  • 1
    This is not specific to clang, I'm able to replicate this with Eclipse 4.4 / CDT 8.4 / **gcc 4.9.1**. No luck whatsoever. – Cengiz Can Sep 04 '14 at 13:01

2 Answers2

0

Try a Enabling "Build output parser". http://www.eclipse.org/forums/index.php/t/501479/

Felipe Lavratti
  • 2,887
  • 16
  • 34
0

I encountered this issue too, other C++11 features are supported, but atomic does not.

rockeet
  • 77
  • 6