sbaratheon
Posts: 69
Joined: Sun Sep 30, 2012 10:33 am

Compiling for c++11

Wed Nov 14, 2012 11:13 pm

I just updated to gcc 4.7 but I'm struggling to compile with the c++11 flag.

My command was:

g++ test.c -std=c++11 -o test.o

but I get:

-bash: -std=gnu++0x: command not found

Any help would be great.

sbaratheon
Posts: 69
Joined: Sun Sep 30, 2012 10:33 am

Re: Compiling for c++11

Wed Nov 14, 2012 11:26 pm

Urgh. I thought I updated gcc but it's still 4.6.3.

How do I update it?

User avatar
joan
Posts: 12738
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Compiling for c++11

Wed Nov 14, 2012 11:36 pm

sudo apt-get install g++-4.7

Perhaps you did install 4.7 but the system is defaulting to an earlier version.

Try

g++-4.7 test.c -std=c++11

sbaratheon
Posts: 69
Joined: Sun Sep 30, 2012 10:33 am

Re: Compiling for c++11

Wed Nov 14, 2012 11:48 pm

Hmm. When I use sudo apt-get install it says g++ is at the latest version (4.7) but g++ -- version says the version is 4.6.3.

sbaratheon
Posts: 69
Joined: Sun Sep 30, 2012 10:33 am

Re: Compiling for c++11

Thu Nov 15, 2012 12:04 am

I want to do this BTW:

Code: Select all

         int x[4];
	           x = {1,2,3,4};

User avatar
joan
Posts: 12738
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Compiling for c++11

Thu Nov 15, 2012 8:26 am

sbaratheon wrote:Hmm. When I use sudo apt-get install it says g++ is at the latest version (4.7) but g++ -- version says the version is 4.6.3.
Use the command

g++-4.7

not

g++

User avatar
joan
Posts: 12738
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Compiling for c++11

Thu Nov 15, 2012 8:29 am

sbaratheon wrote:I want to do this BTW:

Code: Select all

         int x[4];
	           x = {1,2,3,4};
I thought in standard C you could do

int x[4]={1, 2, 3, 4};

BlackJack
Posts: 288
Joined: Sat Aug 04, 2012 8:28 am
Contact: Website

Re: Compiling for c++11

Thu Nov 15, 2012 8:48 am

@joan: You can, but it is not the same if there is code to be executed between the declaration and assigning an „array constant” to it.

Code: Select all

int xs[4];

// Some code goes here…

if (condition) {
    xs = {1, 2, 3, 4};
} else {
    xs = {42, 23, 4711, 0};
} // …

Code: Select all

while not self.asleep():
    sheep += 1

coyotebush
Posts: 12
Joined: Fri Mar 01, 2013 7:39 pm

Re: Compiling for c++11

Wed May 01, 2013 6:19 am

Try the following:
sudo apt-get install g++-4.7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
sudo update-alternatives --config gcc

User avatar
funkyguy4000
Posts: 17
Joined: Mon Mar 25, 2013 2:27 pm

Re: Compiling for c++11

Sat May 23, 2015 5:17 am

Wow this is an old thread
Still helped me out greatly! Thanks!
Accelerate to 88 miles per hour

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 6 guests