Page 1 of 1

C++ 11 and wxWidgets?

Posted: Thu Aug 23, 2012 6:50 pm
by JWS
Hi

I want to hear if anyone uses C++ 11 features (e.g. Lambda expressions) with CodeLite in a wxWidgets application and can recommend how I can get going to use the -std=c++0x compiler setting in a wxwidgets application.

I downloaded the version with CodeLite, Mingw and wxWidgets all in one package (v 4.0.5589). It installed fine, and I used the provided project wizard to create a program with a wx Frame app. It compiled and executed fine.

I found info elsewhere on the web that I have to add -std=c++0x as compiler setting to enable the C++11 features on mingw. But when I use that, I get build errors in wx header files. When I remove the compiler setting the build errors are gone and the wx app runs, but obviously the new C++ features are then also disabled.

Here's my code:

Code: Select all

#include "gui.h"
#include <functional> // included fo lambda expr
///////////////////////////////////////////////////////////////////////////

MainFrameBase::MainFrameBase( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	m_menuBar = new wxMenuBar( 0 );
	m_menuFile = new wxMenu();
	wxMenuItem* menuFileExit;
	menuFileExit = new wxMenuItem( m_menuFile, wxID_EXIT, wxString( _("E&xit") ) + wxT('\t') + wxT("Alt+X"), wxEmptyString, wxITEM_NORMAL );
	m_menuFile->Append( menuFileExit );
	
	m_menuBar->Append( m_menuFile, _("&File") );
	
	this->SetMenuBar( m_menuBar );
	
	wxBoxSizer* mainSizer;
	mainSizer = new wxBoxSizer( wxVERTICAL );
	
	this->SetSizer( mainSizer );
	this->Layout();
	m_statusBar = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
	
	this->Centre( wxBOTH );
	  
	auto test = [](int n){n+=1;};
 
	// Connect Events
	this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( MainFrameBase::OnCloseFrame ) );
	this->Connect( menuFileExit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnExitClick ) );
}
Here's errors I get when I enable the C+11 options.
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

Re: C++ 11 and wxWidgets?

Posted: Thu Aug 23, 2012 7:29 pm
by eranif
JWS wrote:I want to hear if anyone uses C++ 11 features (e.g. Lambda expressions) with CodeLite in a wxWidgets application and can recommend how I can get going to use the -std=c++0x compiler setting in a wxwidgets application.
You should add "-std=gnu++0x" instead of "-std=c++0x"

I havn't tried using lmabda, but this:

Code: Select all

auto s = wxString();
s.Append(wxT("Hello"));
Works.

To save you the next post, you will need to enable clang code completion to get code completion for 'auto' variables
this is done from:

"settings -> tags settings -> clang -> enable clang code completion"

Eran

Re: C++ 11 and wxWidgets?

Posted: Sat Sep 14, 2013 1:36 pm
by petah
eranif wrote:You should add "-std=gnu++0x" instead of "-std=c++0x"
Shouldn't this now be "-std=c++11" ?

I tried searching the forums with "C++11" to find other related threads but phpbb doesn't seem to like the ++, is there a trick to work around this?

thx & cheers,

-- p

Re: C++ 11 and wxWidgets?

Posted: Sat Sep 14, 2013 5:43 pm
by Jarod42
petah wrote:
eranif wrote:You should add "-std=gnu++0x" instead of "-std=c++0x"
Shouldn't this now be "-std=c++11" ?
there is also

Code: Select all

-std=gnu++11
petah wrote: I tried searching the forums with "C++11" to find other related threads but phpbb doesn't seem to like the ++, is there a trick to work around this?
You can use

Code: Select all

c*11
.

Re: C++ 11 and wxWidgets?

Posted: Sat Sep 14, 2013 6:07 pm
by petah
Jarod42 wrote:
petah wrote: I tried searching the forums with "C++11" to find other related threads but phpbb doesn't seem to like the ++, is there a trick to work around this?
You can use

Code: Select all

c*11
.
"Search found 9033 matches"

:)

-- p