【发布时间】: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