【问题标题】:Enable C++17 on Eclipse to use `std::byte`在 Eclipse 上启用 C++17 以使用 `std::byte`
【发布时间】:2018-10-02 08:53:57
【问题描述】:

我想在 eclipse photon 上使用来自 c++17 的 #include <cstddef>std::byte。我已将项目配置为使用 c++17 >> project >> properties >> C/C++ Build >> settings >> GCC C++ Compiler >> Dialect >> Other dialect flags >> -std=c++17 进行编译,并且我也尝试过 -std=c++1z。我下面的程序可以使用<cstddef> 库,但是std::byte 的行无法编译。 Eclipse 说Type 'std::byte' could not be resolved。 如何让 eclipse 支持 C++17?

#include <cstddef>

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

谢谢

【问题讨论】:

  • Type 'std::byte' could not be resolved 是编译器错误还是 Eclipse 消息?哪个编译器+版本?哪个eclipse版本?
  • 这是一条日食消息。我的eclipse版本是Eclipse IDE for C/C++ Developers Version: Photon Release (4.8.0)
  • 尝试直接使用该程序调用 gcc,如果它有效,请告诉我们。 g++ --versiong++ -std=c++17 byte.cppg++ -std=c++1z byte.cpp
  • 好的,g++ --version 命令输出让我感到困惑。它输出g++ (Ubuntu 6.4.0-17ubuntu1~16.04) 6.4.0 20180424。那么,我实际使用的是哪个 C++ 版本?

标签: c++ eclipse c++17


【解决方案1】:

我使用(eclipse 4.7.3agcc 7.3.0 MinGW-W64)。 并且 C++17 与标志 --std=c++1z 一起工作正常@

project >> properties >> C/C++ Build >> settings >> GCC C++ Compiler >> Dialect >> Other dialect flags >> --std=c++1z

【讨论】:

    【解决方案2】:

    根据https://en.cppreference.com/w/cpp/compiler_supportstd::byte 仅从 gcc 7 开始支持。

    尝试升级你的 gcc 版本

    【讨论】:

    • 我成功执行了udo apt install gcc-8sudo apt-get install gcc-8sudo apt-get upgrade gcc。但是当我输入 gcc --versionsudo update-alternatives --config gcc 时,我仍然看不到 gcc 8
    • 最好的解决方案是配置 Eclipse 以使用您的新 gcc(可能命名为 gcc-8g++-8)。另一种是将gccg++程序链接到gcc-8g++-8sudo ln -sf /usr/bin/gcc-8 /usr/bin/gcc
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2017-05-08
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    相关资源
    最近更新 更多