Strange undefined reference to wxXmlResource Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
sunose
Earned a small fee
Earned a small fee
Posts: 16
Joined: Tue Jul 07, 2009 2:01 am

Strange undefined reference to wxXmlResource

Post by sunose » Tue Jul 07, 2009 5:29 am

Hi All:

I am using code;:block 8.0.2 and wxwidget 2.8.10 and mingw (gcc version 3.4.5 (mingw-vista special r3))

use new wxWidgets Project Wizard to create a new project ,using unicode mode.
the wxWidgets 2.8.10 has use UNICODE=1 and USE_GUI=1 build lib with BUILD=release and BUILD=debug to generate two version static lib.

the lib is ok.

now I want to load icon from xrc file,wxrc file work fine and generate the code and head file using wxrc /c /e.

in code has follow Snippets code:

Code: Select all

wxwidgets:
    wxXmlResource::Get()->InitAllHandlers();
   wxIcon moneypig=wxXmlResource::Get()->LoadIcon(wxT("Money_Pig.ico"));
   wxIcon money=wxXmlResource::Get()->LoadIcon(wxT("Money.ico"));

but one class constructure,compile is ok,link has undefined reference error:


wxwidgets:

Code: Select all

testXRCInClassFrame::testXRCInClassFrame(wxFrame *frame)
    : GUIFrame(frame)
{
#if wxUSE_STATUSBAR
    statusBar->SetStatusText(_("Hello Code::Blocks user!"), 0);
    statusBar->SetStatusText(wxbuildinfo(short_f), 1);
#endif
  wxXmlResource::Get()->InitAllHandlers();
   wxIcon moneypig=wxXmlResource::Get()->LoadIcon(wxT("Money_Pig.ico"));
   wxIcon money=wxXmlResource::Get()->LoadIcon(wxT("Money.ico"));
}
after compileed ,when link phase get follow error:

||=== testXRCInClass, Release ===|
obj\Release\testXRCInClassMain.o:testXRCInClassMain.cpp|| undefined reference to `wxXmlResource::Get()'|
obj\Release\testXRCInClassMain.o:testXRCInClassMain.cpp|| undefined reference to `wxXmlResource::InitAllHandlers()'|
...........<skip some error>
||=== Build finished: 12 errors, 0 warnings ===|



but when move the code to App.cpp
link is work.code is follow:
wxwidgets:

Code: Select all

bool testXRCInClassApp::OnInit()
{
    wxXmlResource::Get()->InitAllHandlers();
   wxIcon moneypig=wxXmlResource::Get()->LoadIcon(wxT("Money_Pig.ico"));
   wxIcon money=wxXmlResource::Get()->LoadIcon(wxT("Money.ico"));

    testXRCInClassFrame* frame = new testXRCInClassFrame(0L);
    frame->SetIcon(wxICON(aaaa)); // To Set App Icon
    frame->Show();

    return true;
}
why generate this issue and how to avoid this issue?

thank in advice.

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver » Tue Jul 07, 2009 7:49 am

Hello, during your link phase, did you link with wxXRC ?

Bye.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

sunose
Earned a small fee
Earned a small fee
Posts: 16
Joined: Tue Jul 07, 2009 2:01 am

Post by sunose » Thu Jul 09, 2009 1:55 am

Muetdhiver wrote:Hello, during your link phase, did you link with wxXRC ?

Bye.
yes,unicode enabled XRC static lib libwxmsw28u_xrc.a is linked correct.

sunose
Earned a small fee
Earned a small fee
Posts: 16
Joined: Tue Jul 07, 2009 2:01 am

Post by sunose » Tue Aug 04, 2009 7:21 am

this has been solved:

just include pair header file both in a file:

#include <wx/msw/winundef.h>
#include <wx/xrc/xmlres.h>


winundef.h must be before xmlres.h

this issue come with unicode enabled.

Post Reply