Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 support in Emscripten

I would like to compile a C++ code using Emscripten, where I use some C++11 features. 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.

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")

If it is true, it should wotk, because "Clang 3.3 and later implement all of the ISO C++ 2011 standard."

like image 963
Iter Ator Avatar asked Dec 11 '22 11:12

Iter Ator


1 Answers

Suggestion: add -std=c++11 to your compiler options.

-Wc++11-extensions is a flag to add warnings, not to add C++11 support.

like image 192
max66 Avatar answered Dec 29 '22 00:12

max66