Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling C++11 with g++

Tags:

c++

c++11

flags

g++

I'm trying to update my C++ compiler to C++11. I have searched a bit and I have come to the conclusion that I have to use the flag -std=c++0x or -std=gnu++0x, but I don't know many things about flags. Can anyone help me? (I'm using Ubuntu 12.04.)

Here is the error that I get from the compiler when I attempt to use a library which is included in C++11 (i.e. array):

#include <array> #include <iostream>  int main() {     std::array<int, 3> arr = {2, 3, 5};     ... } 

This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.

like image 309
Rontogiannis Aristofanis Avatar asked Apr 28 '12 12:04

Rontogiannis Aristofanis


People also ask

How do I enable C ++ 11 in G ++?

This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options. In the newest version, you probably have to use -std=c++11 instead.

Can I compile C code with g ++?

g++ also has additional macros. So you can compile C code with g++ and in fact mix both C and C++ code.

How do I know if G ++ supports C ++ 11?

To see if your compiler has C++11 support, run it with just the --version option to get a print out of the version number.

Can I compile C with GCC?

cpp files but they will be treated as C++ files only. gcc can compile any . c or . cpp files but they will be treated as C and C++ respectively.


1 Answers

Flags (or compiler options) are nothing but ordinary command line arguments passed to the compiler executable.

Assuming you are invoking g++ from the command line (terminal):

$ g++ -std=c++11 your_file.cpp -o your_program

or

$ g++ -std=c++0x your_file.cpp -o your_program

if the above doesn't work.

like image 167
Oskar N. Avatar answered Oct 14 '22 04:10

Oskar N.