12-11-2012 07:16 PM
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?
12-12-2012 02:43 AM
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.
12-12-2012 11:39 AM
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/
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/../t
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/
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/../t
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<typenameT, typename... 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)
12-12-2012 03:19 PM
Have you tried Qt code too? If I add QMAKE_CXXFLAGS += -Wc,-std=c++0x even the default QML sample application fails to compile.
12-12-2012 03:31 PM
01-17-2013 07:48 AM - edited 01-17-2013 07:51 AM
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
01-17-2013 02:03 PM
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/
05-11-2013 03:01 AM
QMAKE_CXXFLAGS += -Wc,-std=c++0x
Is "-Wc" a qcc option only thus not available in gcc?