c++ - 在 Mac 上使用 intel 编译器编译 C++ 代码时出现错误 : expected an identifier

标签 c++ macos compiler-errors compilation intel

我的笔记本电脑从昨天开始就无法编译简单的 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,它是从适用于 C++ macOS 的英特尔® Parallel Studio XE Composer 版本安装的。

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

  • 如果我使用 gnu 编译器,它工作得很好。而我的代码需要使用intel的编译器。

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

================================================== ======================= 更新1:问题是在我更新“Xcode 命令行工具”后发生的。看起来 /Library/Developer/CommandLineTools/usr/include/c++/ 不正确。

================================================== ======================= 更新2:可以使用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:

最佳答案

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

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

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

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

关于c++ - 在 Mac 上使用 intel 编译器编译 C++ 代码时出现错误 : expected an identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46355820/

相关文章:

c++ - 如何将 std::bind 对象传递给函数

c++ - Boost、asio、https 和主机/证书验证

python - 无法在 MAC OS 中通过 pip 安装 rpy2

在 IPhone/ATT 上进行网络共享时出现 Python FTP SSL 错误

c - 尝试让 GetPrimaryMACAddress 停止打印详细信息

c++ - 模板类中构造函数的语法

java - 作业的左侧是否必须为变量?

c++ - 如何从三个整数(或者可能是一个 git/SVN commit/rev.string)生成一个 constexpr 版本字符串?

c++ - 在对话框中以编程方式更改 Tab 键顺序的其他方法

c# - 使用NCrunch,FxCop分析仪和 “warnings as errors” : How to configure warning severity in NCrunch?