C++ 11 and wxWidgets?

General questions regarding the usage of CodeLite
JWS
CodeLite Curious
Posts: 1
Joined: Thu Aug 23, 2012 6:18 pm
Genuine User: Yes
IDE Question: C++
Contact:

C++ 11 and wxWidgets?

Post 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
User avatar
eranif
CodeLite Plugin
Posts: 6372
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: C++ 11 and wxWidgets?

Post 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
Make sure you have read the HOW TO POST thread
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: C++ 11 and wxWidgets?

Post 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
main: Debian Jessie x64 + custom wxTrunk
User avatar
Jarod42
CodeLite Expert
Posts: 237
Joined: Wed Sep 30, 2009 5:54 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: C++ 11 and wxWidgets?

Post 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
.
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: C++ 11 and wxWidgets?

Post 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
main: Debian Jessie x64 + custom wxTrunk
Post Reply