【问题标题】:compiling C++ code with intel compiler on Mac error: expected an identifier在 Mac 上使用英特尔编译器编译 C++ 代码错误:需要一个标识符
【发布时间】:2018-03-03 12:11:30
【问题描述】:

我的笔记本从昨天开始就不能编译一个简单的c++代码,以前它运行得很好。

c++ 代码可以是 main.cpp 文件中的 hello-world 代码。

#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    cout<<"Hello World"<<endl;

    return 0;
}

我正在尝试编译代码

icpc main.cpp

错误信息是

在 /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm(637) 包含的文件中, 来自 /Library/Developer/CommandLineTools/usr/include/c++/v1/__string(56), 来自 /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view(171), 来自 /Library/Developer/CommandLineTools/usr/include/c++/v1/string(470), 来自 /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale(15), 来自 /Library/Developer/CommandLineTools/usr/include/c++/v1/ios(216), 来自 /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream(38), 来自 main.cpp(1): /Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits(2065):错误:需要一个标识符 : public decltype((_VSTD::__is_assignable_test<_tp _arg>(0))) {};

main.cpp 的编译中止(代码 2)

一些信息:

  • 我使用的是 icpc (ICC) 17.0.4 20170411,它是从 Intel® Parallel Studio XE Composer Edition for C++ macOS 安装的。

  • 我的 Mac 是 MacBook Pro(15 英寸,2017 年),版本 10.12.6。

  • 如果我使用 gnu 编译器,它可以正常工作。而我的代码需要使用英特尔的编译器。

  • 以前的代码可以用,不知道什么时候变成这个。我已经尝试过重启系统。

================================================ ======================== Update1:问题发生在我更新“Xcode 命令行工具”之后。 /Library/Developer/CommandLineTools/usr/include/c++/ 好像不对。

================================================ ======================== Update2:这可以通过icpc -std=c++11 main.cpp解决

但是,当我将 main.cpp 更改为

#include <iostream> 
#include <vector>
#include <tuple>

using namespace std;

tuple<vector<int>, vector<int>, vector<int>> 
getAllBlockMeanErrorTuple(const vector<int> &vec)
{
    vector<int> fact, mean, err;
    fact.resize( vec.size() );
    mean.resize( vec.size() );
    err.resize(  vec.size() );
    return make_tuple(fact, mean, err);
}


int main(int argc, char** argv)
{
    cout<<"Hello World"<<endl;

    return 0; 
}

即使我使用icpc -std=c++11 main.cpp,它仍然有错误

/Library/Developer/CommandLineTools/usr/include/c++/v1/__tuple(401): error: type name is not allowed
  -> __all<typename enable_if<_Trait<_LArgs, _RArgs>::value, bool>::type{true}...>;

      detected during:

【问题讨论】:

  • 您确定要将其编译为 C++,而不是 C?如果您不小心将编译器设置为“选择语言”中的“编译为 C”,那就可以解释了。或者您对系统上的 C++ 头文件进行了更新,它们不再与您的实际编译器兼容(例如 C++14 而不是 C++11)
  • @MatsPetersson:icpc 是 C++ 编译器。如果没有 -xc 参数,它应该编译为 C++。也许OP需要-std=gnu++14或其他东西;因为他们似乎将icpc 与系统C++ 头文件一起使用。或者 icpc 可能不会接受 decltype,但 clang 会。 (不过,我认为 gcc 不会)
  • 尝试将 -std=c++11 添加到标志中。
  • 谢谢大家的建议。 -std=c++11 标志有效。但是,当我尝试使用元组时,它也有同样的问题。为什么我的 intel 编译器试图包含 /Library/Developer/CommandLineTools/usr/include/c++/ 标头,我可以包含 intel c++ 的其他标头吗?
  • 我更新上面的问题和错误信息。

标签: c++ macos compiler-errors compilation intel


【解决方案1】:

我在将命令行工具升级到 2017 年 9 月的版本时遇到了同样的问题

虽然没有找到合适的解决方案,但我重新安装了以前版本(2017 年 4 月)的命令行工具并解决了问题 (https://developer.apple.com/download/more/#)。

我期待有一个干净的解决方案。

编辑(2017 年 5 月 12 日): 我通过使用 gcc 重新编译所有内容解决了这个问题。在编译时,英特尔编译器将使用响应路径中的gccg++ 的编译器。在/usr/local/bin 中使用自制软件和一些符号链接的安装将新安装的gcc 推送到clang 前面,然后避免gcc 在每次系统更新时更改。希望对您有所帮助。

【讨论】:

    【解决方案2】:

    尝试检查您是否使用了正确的设置 并且 GNU 正在工作,因为它自动设置为 C++ 尝试将编译器设置为 c++ 希望这有效。 或者您可以使用 xcode 编写 c++ 代码。

    【讨论】:

    • 谢谢你,赞恩。我可以用gnu编译。你建议如何检查我的设置?
    猜你喜欢
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多