User forums > Help
C++11 enabling problem
AeroWB:
Before submitting a bug report I wanted to check if this is indeed a bug or if I am missing something.
I am using Code::Blocks 13.12 on Ubuntu 14.04 LTS 64 bit on a Lenovo X240 Core i5 laptop.
My project requires the use of the C++ 2011 standard. So I went to project -> build options -> compiler flags and enable the build in "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]" This adds the <Add option="-std=c++11" /> before the -Wall and -fexception options in the Project file, just as expected. However when compiling this option is ignored and the build log shows that only the -Wall and -fexceptions options are used.
I tried adding this option to target build option instead of the project build option but that did not help.
I tried adding the -std=gnu++11 option, but this also gets ignored.
Now I also added the -std=c++11 option to project -> build options -> other options. This option is also listed in the project file as a second <Add option="-std=c++11" /> below the -Wall and -fexception options and now when I press compile it works, the -std=c++11 is listed on the build log once after -Wall and -fexceptions.
Now when I disable the build in "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]" copiler option, the <Add option="-std=c++11" /> is only in my project file once and it is still listed below -Wall and -fexception options but the project does not compile as the build log shows only the -Wall and -fexception options being used.
Conclusion: I have to add the -std=c++11 twice to enable it, and the same is true for the -std=gnu+11 option. Is this normal and by design or is this a Code::Blocks bug?
MortenMacFly:
...could you provide a sample project file, please? (It works just fine here...)
killerbot:
I use this everyday and it works.
Can you enable in the compiler settings that it shows the full log (command) on the compiler invocation ,and paste it here please ?
AeroWB:
Thanks for the replies, interesting to hear it just works for some.
The problem is even weirder as my project file which has both -std=c++11 options is not working when I load it in Code::Blocks, I have to add the c++11 option again in the build options before it works.
When I open below project and press build it fails with the error:
-------------- Build: Debug in wb (compiler: GNU GCC Compiler)---------------
gcc -Wall -fexceptions -pthread -g -c /home/willem/Documents/CodeBlocksProjects/wb/wb.cc -o obj/Debug/wb.o
In file included from /usr/include/c++/4.8/thread:35:0,
from /home/willem/Documents/CodeBlocksProjects/wb/wb.cc:16:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
And a lot more error after that.
Now when I right-click the project, select build options -> other options and add -std=c++11 the project builds ok.
If I remove all -std=c++11 options from the project file, open the project, right-click the project, select build options -> other options and add -std=c++11 Code::Blocks says: The compiler flags -std=c++11 were stated in 'Other options' but unchecked in 'Compiler Flags'. Do you want to enable these flags?
When I select Yes and Build the project fails.
When I select No and Build the project also fails.
When I select Yes, right-click the project, select build options -> other options and add -std=c++11 again and Build the project works (and the project file has 2 times the c++11 defined but opening the project removes the c++11 option from other options and it will fail)
So I have to select the c++11 compiler flag once and I have to add the same setting to other options every time I open the project.
Project File:
--- Code: ---<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="wb" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/wb" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Option projectLinkerOptionsRelation="0" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add option="-pthread" />
<Add option="-std=c++11" />
</Compiler>
<Linker>
<Add option="-pthread" />
</Linker>
<Unit filename="include/linux/can.h" />
<Unit filename="wb.cc">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
--- End code ---
oBFusCATed:
--- Quote from: AeroWB on August 19, 2014, 08:28:55 pm ---gcc -Wall -fexceptions -pthread -g -c /home/willem/Documents/CodeBlocksProjects/wb/wb.cc -o obj/Debug/wb.o
--- End quote ---
Are you sure you've setup the compiler correctly?
Can you verify that the c++ compiler in the toolchain executables is set to g++ and not gcc?
gcc is the C language compiler, g++ is the one for C++!
Navigation
[0] Message Index
[#] Next page
Go to full version