4

I want to use #include <cstddef> and std::byte from c++17 on eclipse photon. I have configured the project to compile using c++17 >> project >> properties >> C/C++ Build >> settings >> GCC C++ Compiler >> Dialect >> Other dialect flags >> -std=c++17 and I have also tried -std=c++1z. My program below can use <cstddef> library, but the line with std::byte does not compile. Eclipse says Type 'std::byte' could not be resolved. How do I make eclipse support C++17?

#include <cstddef>

int main(void) {
    std::byte myByte { 2 };
}

Thanks

Felipe
  • 7,013
  • 8
  • 44
  • 102
  • 1
    Is `Type 'std::byte' could not be resolved` a compiler error or an eclipse message? Which compiler + version? Which eclipse version? – mch Oct 02 '18 at 08:55
  • It is an eclipse message. My eclipse version is `Eclipse IDE for C/C++ Developers Version: Photon Release (4.8.0)` – Felipe Oct 02 '18 at 08:57
  • 2
    Try and invoke gcc directly with that program and tel us if it works. `g++ --version` and `g++ -std=c++17 byte.cpp` or `g++ -std=c++1z byte.cpp`. – YSC Oct 02 '18 at 09:05
  • ok, `g++ --version` command output is something that is confusing me. It outputs `g++ (Ubuntu 6.4.0-17ubuntu1~16.04) 6.4.0 20180424`. So, which C++ version I am actually using? – Felipe Oct 02 '18 at 09:15
  • I have long suspected that the eclipse indexer is too detached from how a source file is going to be compiled. It's more than likely that your code and compilation is fine, but the indexer chokes because the standard library header defines `std::byte` conditionally, based on language standard. Since you had to specify `-std=C++17` as an "other option", the indexer probably doesn't have a clue, and therefore you get this annoying message. – StoryTeller - Unslander Monica Oct 02 '18 at 09:16
  • Possible solution: https://stackoverflow.com/questions/17131744/eclipse-cdt-indexer-does-not-know-c11-containers/24628885#24628885 – Galik Oct 02 '18 at 10:14
  • didn't work @Galik. I am using a shared library and When I disable `CDT User Setting Entries` and `CDT GCC Built-in Compiler Settings` the project that test my shared library does not work anymore. – Felipe Oct 02 '18 at 10:27
  • @YSC, I compiled on the command line usin `g++ -std=c++17` and I still get the error `‘byte’ is not a member of ‘std’` – Felipe Oct 02 '18 at 10:41
  • I have installed gcc-8, but when I execute `sudo update-alternatives --config gcc` it does not show gcc-8 to use. Only shows version 6 and 4.8 – Felipe Oct 02 '18 at 10:46
  • 1
    Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181146/discussion-between-galik-and-felipe-oliveira-gutierrez). – Galik Oct 02 '18 at 10:46

2 Answers2

4

I use (eclipse 4.7.3a and gcc 7.3.0 MinGW-W64). And C++17 works fine with flag --std=c++1z

project >> properties >> C/C++ Build >> settings >> GCC C++ Compiler >> Dialect >> Other dialect flags >> --std=c++1z
Simson
  • 3,373
  • 2
  • 24
  • 38
1

According to https://en.cppreference.com/w/cpp/compiler_support,std::byte is only supported since gcc 7.

Try upgrade your gcc version

Irda
  • 81
  • 4
  • I executed `udo apt install gcc-8`, `sudo apt-get install gcc-8`, `sudo apt-get upgrade gcc` with success. But I still cannot see gcc 8 when I type `gcc --version` or `sudo update-alternatives --config gcc` – Felipe Oct 02 '18 at 09:51
  • The best solution is to configure Eclipse to use your new gcc (which is probably named `gcc-8` and `g++-8`). The other one is to link `gcc` and `g++` program to `gcc-8` and `g++-8` : `sudo ln -sf /usr/bin/gcc-8 /usr/bin/gcc` – Irda Oct 02 '18 at 09:57