Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Native Development

Reply
New Contributor
radub
Posts: 4
Registered: ‎12-11-2012
My Carrier: telus

is c++11 supported?

How can the c++11 features supported by g++ 4.6.3 ( as described in http://gcc.gnu.org/gcc-4.6/cxx0x_status.html) be enabled?

Please use plain text.
Trusted Contributor
Zingam
Posts: 135
Registered: ‎05-09-2012

Re: is c++11 supported?

Use these

 

 -Wc, -std=c++0x

 

but don't do it. It appears that it doesn't compile properly anyting yet. And I haven't read anywhere that there will be an official support.

Please use plain text.
New Contributor
radub
Posts: 4
Registered: ‎12-11-2012
My Carrier: telus

Re: is c++11 supported?

Actually my experience - after fiddling with the settings for a couple of hours - is different. It seems there is support (at the 4.6 level) for c++11 features.

1:std=c++0x is not enough - gnu c++ library has to be used instead of dinkum (that is outdated anyway) and it has to be set both at compiler and linker level

2:for the simulator the architecture has to be enforced (there might be runtime surprises on the real device - I don't have one to try)

3:-lstdc++ has to be enforced

 

this is an example build for simulator:

qcc -o src/a.o ../src/a.cpp -V4.6.3,gcc_ntox86_cpp -w1 -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/freetype2 -I/Applications/bbndk/target_10_0_9_1673/qnx6/../target-override/usr/include -D_FORTIFY_SOURCE=2 -c -O0 -g -fstack-protector-strong -V4.6.3,gcc_ntox86_gpp -march=i486 -Wc,-std=c++0x

qcc -o tst src/a.o -lstdc++ -V4.6.3,gcc_ntox86_cpp -w1 -lang-c++ -g -Wl,-z,relro -Wl,-z,now -L/Applications/bbndk/target_10_0_9_1673/qnx6/../target-override/x86/lib -L/Applications/bbndk/target_10_0_9_1673/qnx6/../target-override/x86/usr/lib -V4.6.3,gcc_ntox86_gpp

 

and this is for the device-release:

qcc -o src/a.o ../src/a.cpp -V4.6.3,gcc_ntoarmv7le_cpp -w1 -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/freetype2 -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/c++/4.6.3 -I/Applications/bbndk/target_10_0_9_1673/qnx6/../target-override/usr/include -D_FORTIFY_SOURCE=2 -c -O2 -fstack-protector-strong -fPIE -V4.6.3,gcc_ntoarmv7le_gpp -frecord-gcc-switches -Wc,-std=c++0x

qcc -o tst src/a.o -lstdc++ -V4.6.3,gcc_ntoarmv7le_cpp -w1 -lang-c++ -Wl,-z,relro -Wl,-z,now -pie -L/Applications/bbndk/target_10_0_9_1673/qnx6/../target-override/armle-v7/lib -L/Applications/bbndk/target_10_0_9_1673/qnx6/../target-override/armle-v7/usr/lib -V4.6.3,gcc_ntoarmv7le_gpp

 

I can compile and run (simulator) code like:

 


 

#include<vector>

#include<iostream>

#include<numeric>

#include<algorithm>

#include<memory>

#include<utility>

#include<string>

#include<stdexcept>

#include<thread>

 

void doSomeWork( void )

{

    std::cout << "hello from thread..." << std::endl;

    return;

}

 

 

void mprintf(const char* s)

{

    while (*s) {

        if (*s == '%' && *(++s) != '%')

            throw std::runtime_error("invalid format string: missing arguments");

        std::cout << *s++;

    }

}

 

template<typenameTtypename... Args>

void mprintf(const char* s, T value, Args... args)

{

    while (*s) {

        if (*s == '%' && *(++s) != '%') {

        T& t = value;

            std::cerr << t;

            mprintf(s, args...); // call even when *s == 0 to detect extra arguments

            return;

        }

        std::cout << *s++;

    }

    throw std::logic_error("extra arguments provided to printf");

}

 

classMovable

{

Movable (Movable&&); //move constructor

Movable&& operator=(Movable&&); //move assignment operator

};

 

 

structFoo {

    Foo() { std::cout << "Foo::Foo\n"; }

    ~Foo() { std::cout << "Foo::~Foo\n"; }

    void bar() { std::cout << "Foo::bar\n"; }

};

 

void f(const Foo &foo)

{

    std::cout << "f(constFoo&)\n";

}

 

 

int main()

 

{

std::thread t( doSomeWork );

t.join();

int a[5]={0};

char c[3]={0};

std::iota(a, a+5, 10); //changes a to {10,11,12,13,14}

std::iota(c, c+3, 'a');

std::vector<int> v{6, 2};

 

for ( auto itr = v.begin(), end = v.end(); itr != end; itr++ )

{

    std::cerr << *itr;

}

 

  if (std::all_of(v.cbegin(), v.cend(), [](int i){ return i % 2 == 0; })) {

        std::cout << "All numbers are even\n";

    }

 

auto func = [] () { std::cerr << "Hello world"; };

    func(); // now call the function

 

    std::string s1("test");

        std::string s2("test2");

        int r = 9;

        int y = 2;

        mprintf("% - %", s1, y);

 

        std::unique_ptr<Foo> p1(new Foo);  // p1 owns Foo

          if (p1) p1->bar();

 

          {

              std::unique_ptr<Foo> p2(std::move(p1));  // now p2 owns Foo

              f(*p2);

 

              p1 = std::move(p2);  // ownership returns to p1

              std::cout << "destroying p2...\n";

          }

 

          if (p1) p1->bar();

          return 1;

}


 

 This is a collection of some c++11 features available in g++ 4.6 (std::thread included)

 

 

 

Please use plain text.
Trusted Contributor
Zingam
Posts: 135
Registered: ‎05-09-2012

QtRe: is c++11 supported?

Have you tried Qt code too? If I add QMAKE_CXXFLAGS += -Wc,-std=c++0x even the default QML sample application fails to compile.

Please use plain text.
New Contributor
radub
Posts: 4
Registered: ‎12-11-2012
My Carrier: telus

Re: QtRe: is c++11 supported?

No - native only
Please use plain text.
Contributor
juergen0815
Posts: 30
Registered: ‎02-23-2012
My Carrier: Bell

Re: is c++11 supported?

[ Edited ]

Thanks. The tip with the -lang-c++ worked. At least for some aspects.

 

This works:

 

#include <iostream>
#include <vector>

 

int main()

{
    int* null = nullptr;
    std::vector<int> foo;
    for ( auto i = foo.begin(); i < foo.end(); ++i ) {
         std::cout << *i << std::endl;
    }
    std::cout << "Hello World!" << std::endl;
    return 0;
}

 

This does not:

 

#include <iostream>
#include <vector>

 

int main()
{
    int* null = nullptr;
    std::vector<int> foo = { 1,2,3,4 };
    for ( auto i : foo ) {
         std::cout << i << std::endl;
    }
    std::cout << "Hello World!" << std::endl;
    return 0;
}

 

(code compiles fine in mingw 4.6 and ndk8/gcc4.6)

 

BTW full cmd line:

 

C:\bbndk-10.0.9>qcc -Wc,-std=c++0x -lang-c++ -lstdc++ hello.cpp

Please use plain text.
New Contributor
radub
Posts: 4
Registered: ‎12-11-2012
My Carrier: telus

Re: is c++11 supported?

 

 

int* null = nullptr;

    std::vector<int> foo = { 1,2,3,4 };

    for ( auto i : foo ) {

        std::cout << i << std::endl;

    }

compiles perfectly well with:

 

qcc -o src/a.o ../src/a.cpp -V4.6.3,gcc_ntox86_cpp -w1 -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/freetype2 -I/Applications/bbndk/target_10_0_9_1673/qnx6/../target-override/usr/include -D_FORTIFY_SOURCE=2 -c -O0 -g -fstack-protector-strong -V4.6.3,gcc_ntox86_gpp -march=i486 -Wc,-std=c++0x

Please use plain text.
Trusted Contributor
Zingam
Posts: 135
Registered: ‎05-09-2012

Re: is c++11 supported?

QMAKE_CXXFLAGS += -Wc,-std=c++0x

Is "-Wc" a qcc option only thus not available in gcc?

Please use plain text.