Tag Archives: C++11

Using C++11 Lambdas with ELLCC

A recent post on C++11 lambdas and a forum question led me to this topic. Lambdas are a new C++ feature, described very well in the first link. The forum post asked how to build a simple test program using lambdas with ellcc:

#include <functional>
#include <iostream>
#include <string>
int main(int argc, char **argv){
    std::string test;
    test += "Hello World!";
    std::cout << test << std::endl;
    auto lambda = [&](const std::string &in) -> void {
        std::cout << "Text was: " << in << std::endl;
        return;
    };
    lambda("extra text.");
    return 0;
}

The simple solution was:

[~] dev% ellcc/bin/ecc++ -target x86_64-ellcc-linux --std=c++11 test.cpp
[~] dev% ./a.out
Hello World!
Text was: extra text.
[~] dev%

The important thing here is that you need the -target option to set the appropriate target environment and you need to specify --std=c++11 to enable C++11 language features.