简体   繁体   English

在Mac上使用Intel编译器编译C ++代码时出现错误:预期为标识符

[英]compiling C++ code with intel compiler on Mac error: expected an identifier

My laptop can not compile a simple c++ code since yesterday, it works perfectly fine before. 从昨天开始,我的笔记本电脑无法编译简单的C ++代码,之前它的运行情况非常好。

The c++ code is can be a hello-world code in main.cpp file. C ++代码可以是main.cpp文件中的hello-world代码。

#include <iostream>

using namespace std;

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

    return 0;
}

I am trying to compile the code by 我正在尝试通过编译代码

icpc main.cpp

The error information is 错误信息是

In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm(637), from /Library/Developer/CommandLineTools/usr/include/c++/v1/__string(56), from /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view(171), from /Library/Developer/CommandLineTools/usr/include/c++/v1/string(470), from /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale(15), from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios(216), from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream(38), from main.cpp(1): /Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits(2065): error: expected an identifier : public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {}; 在/ 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) )){};

compilation aborted for main.cpp (code 2) main.cpp的编译中止(代码2)

A few information: 一些信息:

  • I am using icpc (ICC) 17.0.4 20170411, it is installed from Intel® Parallel Studio XE Composer Edition for C++ macOS. 我正在使用icpc(ICC)17.0.4 20170411,它是从适用于C ++ macOS的英特尔®Parallel Studio XE Composer Edition安装的。

  • My mac is MacBook Pro (15-inch, 2017), version 10.12.6. 我的Mac是MacBook Pro(15英寸,2017年),版本10.12.6。

  • If I use gnu compiler, it works fine. 如果我使用gnu编译器,则可以正常工作。 While my code needs to use intel's compiler. 虽然我的代码需要使用intel的编译器。

  • The code works before, do not know while it becomes this. 该代码之前工作,不知道它变成了什么。 I have already tried restarting the systems. 我已经尝试过重新启动系统。

====================================================================== Update1 : The problem happened after I update my "Command Line Tools for Xcode". ================================================== =================== Update1 :更新我的“ Xcode命令行工具”后发生了问题。 It looks like the /Library/Developer/CommandLineTools/usr/include/c++/ is not right. 看起来/Library/Developer/CommandLineTools/usr/include/c++/是不正确的。

====================================================================== Update2 : This is can be solved by using icpc -std=c++11 main.cpp ================================================== =================== Update2 :这可以通过使用icpc -std=c++11 main.cpp来解决

However when I change my main.cpp to 但是当我将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; 
}

It has error again even if I use icpc -std=c++11 main.cpp 即使我使用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:

I encountered the same issue while upgrading command line tools to the version of September 2017 在将命令行工具升级到2017年9月版本时遇到了相同的问题

While not finding a proper solution, I reinstalled previous version ( April 2017) of command line tools and it solved the problem ( https://developer.apple.com/download/more/# ). 在找不到合适的解决方案的同时,我重新安装了命令行工具的先前版本(2017年4月),并解决了该问题( https://developer.apple.com/download/more/# )。

I am looking forward to having a clean solution. 我期待有一个干净的解决方案。

EDIT (5/12/17): I solved the issue by recompiling everything using gcc. 编辑(5/12/17):我通过使用gcc重新编译所有内容解决了该问题。 At compilation, Intel compilers will use the compiler that responds to gcc and g++ in the path. 编译时,英特尔编译器将使用对路径中的gccg++进行响应的编译器。 An installation with homebrew and some symlink in /usr/local/bin pushes the newly installed gcc in front of clang and then avoids gcc to change at each system update. /usr/local/bin使用自制软件和一些符号链接进行的安装会将新安装的gcc推到clang前面,然后避免在每次系统更新时gcc都进行更改。 Hope it helps. 希望能帮助到你。

Try to check that you are using right settings and GNU is working because it automatically set to C++ try to set compiler to c++ hope this works. 尝试检查您使用的设置是否正确,并且GNU是否可以正常工作,因为它会自动设置为C ++并尝试将编译器设置为c ++,希望这样做可以。 OR You can use xcode to write c++ Code. 或可以使用xcode编写c ++代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM