[英]C++11 support in Emscripten
I would like to compile a C++ code using Emscripten, where I use some C++11 features. 我想使用Emscripten编译一个C ++代码,我在其中使用了一些C ++ 11特性。 Unfortunately I get an error:
不幸的是我收到一个错误:
index.cpp:13:18: error: expected expression
vv.push_back({1.5f, 2.f});
^
index.cpp:14:18: error: expected expression
vv.push_back({5.f, 0});
^
index.cpp:15:18: error: expected expression
vv.push_back({1, 1});
^
index.cpp:17:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto& item : vv) {
^
index.cpp:17:20: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for(auto& item : vv) {
I can't understand, why I get this errors. 我无法理解,为什么我会得到这个错误。 The newest Emscripten and Clang versions are activated using
emsdk
. 最新的Emscripten和Clang版本使用
emsdk
激活。
The code is: 代码是:
#include<iostream>
#include<vector>
struct AA {
float a;
float b;
};
int main() {
std::vector<AA> vv;
vv.push_back({1.5f, 2.f});
vv.push_back({5.f, 0});
vv.push_back({1, 1});
for(auto& item : vv) {
std::cout << item.a << ' ' << item.b << std::endl;
}
}
I even get a message: LLVM version appears incorrect (seeing "4.0", expected "3.7")
我甚至收到一条消息:
LLVM version appears incorrect (seeing "4.0", expected "3.7")
If it is true, it should wotk, because "Clang 3.3 and later implement all of the ISO C++ 2011 standard." 如果确实如此,它应该是wotk,因为“Clang 3.3及更高版本实现了所有ISO C ++ 2011标准。”
Suggestion: add -std=c++11
to your compiler options. 建议:将
-std=c++11
添加到编译器选项中。
-Wc++11-extensions
is a flag to add warnings, not to add C++11 support. -Wc++11-extensions
是添加警告的标志,而不是添加C ++ 11支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.