Author Topic: Enjoying C++11 Experience with Code::Blocks  (Read 9112 times)

Offline cpp_lover

  • Single posting newcomer
  • *
  • Posts: 5
Enjoying C++11 Experience with Code::Blocks
« on: August 29, 2012, 12:03:42 pm »
Hi Everyone,

I would like to try out the exciting features offered by the new C++11 Standard using CodeBlocks. I heard that TDM-GCC 4.6.1 implemented many of the features. I have downloaded and installed it on my PC. But I am wondering how to integrate it with CodeBlocks 10.05.

Kindly have a look at the attached picture showing global compiler settings I have on CodeBlocks. In particular I need to put proper paths and files for:

C++ compiler:
Linker for dynamic libs:
Linker for static libs:
Debugger:
Resource compiler:
Make program:

As you can see, the current installation directory I have is
C:\Program Files\CodeBlocks\MinGW

I know that I need to change it to the TDM-GCC directory which for me is
C:\TDM-GCC

Also, I think I need to select this compiler flag:
-std=c++0x
Please help me with the fields above (shown in the attached picture also) and let me know if I am missing anything.

Thank you all.

----- cpp_lover

[attachment deleted by admin]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #1 on: August 29, 2012, 12:58:51 pm »
I know that I need to change it to the TDM-GCC directory which for me is
C:\TDM-GCC

[...]

Also, I think I need to select this compiler flag:
-std=c++0x
So why don't you simply do it?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #2 on: August 29, 2012, 01:06:25 pm »
Better use -std=c++0x -U__STRICT_ANSI__ or you will run into trouble when including headers like cstdio (or when using a third-party library that does this).

Other than that, nothing to be done.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline cpp_lover

  • Single posting newcomer
  • *
  • Posts: 5
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #3 on: August 29, 2012, 01:18:26 pm »
Thomas,

Thanks. But how do I add a new flag. I can only see a built in flag which is -std = c++0x which I can only select/unselect.

MortenMacfly,

If you saw, I attached a snapshot. I needed to know what to put in these fields:

C++ compiler:
Linker for dynamic libs:
Linker for static libs:
Debugger:
Resource compiler:
Make program:

However, I have put another attachment just now. Please see if I have put the right things in the fields.

[attachment deleted by admin]

[attachment deleted by admin]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #4 on: August 29, 2012, 01:26:34 pm »
Put flags not in the list into other options (the same way you would do it at the commandline).

Offline cpp_lover

  • Single posting newcomer
  • *
  • Posts: 5
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #5 on: August 29, 2012, 01:52:43 pm »
Thank you. I put the following:

-std=c++0x -U__STRICT_ANSI__

But I am having a strange problem.

I have it in the beginning of my code: #include <iostream>

Yet, I am having this strange error: "undefined reference to std::cout"

Purplexing. :-(

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5494
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #6 on: August 29, 2012, 01:59:22 pm »
Better use -std=c++0x -U__STRICT_ANSI__ or you will run into trouble when including headers like cstdio (or when using a third-party library that does this).

Other than that, nothing to be done.
Could you explain a bit more Thomas, about those potential issues ?
We are using '-std=c++0x" for 2 years (without -U__STRICT_ANSI__), and that header has been included, haven't seen any problems.

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #7 on: August 29, 2012, 02:18:48 pm »
With GCC4.6.1-TDM you should use:
Code
-std=gnu++0x

Eran

zabzonk

  • Guest
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #8 on: August 29, 2012, 03:10:18 pm »
Quote
With GCC4.6.1-TDM you should use: -std=gnu++0x

Why? -std=c++0x works perfectly well.

zabzonk

  • Guest
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #9 on: August 29, 2012, 03:14:32 pm »
Quote
Yet, I am having this strange error: "undefined reference to std::cout"

That's a linker error, including <iostream> is not sufficient to solve it - for some reason you are not linking with the C++ libraries.

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #10 on: August 29, 2012, 03:55:42 pm »
Quote
Why? -std=c++0x works perfectly well.
On my machine, using GCC-4.6.1-TDM / wxWidgets 29.4 you get errors if you try to use something like:

Code
auto s = wxString("Hello world");

The only thing that fixes this is changing the flag:
Code
-std=c++0x 
to
Code
-std=gnu++0x

If I change to a different compiler (GCC4.7.1 from MinGW) - then it is working
Note that this is true for Windows only with this specific compiler

Here is the compiler output (g++ is 4.6.1 from TDM):

Code
g++ -c "c:/cp/CdeLiteHello/HelloWorld/gui.cpp" -std=c++0x -g -Wall -O0 -mthreads -DHAVE_W32API_H -D__WXMSW__ -D__WXDEBUG__ -D_UNICODE -IC:\wxWidgets-2.9.4\lib\gcc_dll\mswud -IC:\wxWidgets-2.9.4\include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -D__WX__ -o ./Debug/gui.o -I. 
In file included from C:\wxWidgets-2.9.4\include/wx/string.h:50:0,
from C:\wxWidgets-2.9.4\include/wx/intl.h:17,
from c:/cp/CdeLiteHello/HelloWorld/gui.h:11,
from c:/cp/CdeLiteHello/HelloWorld/gui.cpp:8:
C:\wxWidgets-2.9.4\include/wx/wxcrtbase.h: In function 'char* wxStrdup(const char*)':
C:\wxWidgets-2.9.4\include/wx/wxcrtbase.h:697:62: error: '_strdup' was not declared in this scope
In file included from C:\wxWidgets-2.9.4\include/wx/intl.h:17:0,
from c:/cp/CdeLiteHello/HelloWorld/gui.h:11,
from c:/cp/CdeLiteHello/HelloWorld/gui.cpp:8:
C:\wxWidgets-2.9.4\include/wx/string.h: In function 'int Stricmp(const char*, const char*)':
C:\wxWidgets-2.9.4\include/wx/string.h:174:31: error: 'strcasecmp' was not declared in this scope
mingw32-make.exe[1]: *** [Debug/gui.o] Error 1

Eran
« Last Edit: August 29, 2012, 03:58:52 pm by eranif »

Offline cpp_lover

  • Single posting newcomer
  • *
  • Posts: 5
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #11 on: August 29, 2012, 05:02:06 pm »
Hi Neil,

Am I doing something wrong here since I have the linker error? I have the following files selected on the Toolchain executables tab:

Compiler installation directory: C:\tdmgcc
C compiler: mingw32-gcc-4.6.1.exe
C++ compiler: mingw32-g++.exe
Linker for dynamic libs: ld.exe
Linker for static libs: ar.exe
Debugger: gdb.exe
Resource compiler: windres.exe
Make program: mingw32-make.exe

Kindly have a look at the attached picture and reply. Thanks.

Offline cpp_lover

  • Single posting newcomer
  • *
  • Posts: 5
Re: Enjoying C++11 Experience with Code::Blocks
« Reply #12 on: August 29, 2012, 05:32:17 pm »
I found the mistake finally. :-)

Incorrect setting is
Linker for dynamic libs: ld.exe

Correct setting is
Linker for dynamic libs: mingw32-g++.exe

On that tab, all other settings remain the same as above. So what I should have is like below.

Compiler installation directory: C:\tdmgcc
C compiler: mingw32-gcc-4.6.1.exe
C++ compiler: mingw32-g++.exe
Linker for dynamic libs: mingw32-g++.exe
Linker for static libs: ar.exe
Debugger: gdb.exe
Resource compiler: windres.exe
Make program: mingw32-make.exe

Thanks, everyone.
« Last Edit: August 29, 2012, 05:35:55 pm by cpp_lover »