Problem using custom events Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Lamego
Earned some good credits
Earned some good credits
Posts: 101
Joined: Wed Jun 29, 2005 10:13 pm
Location: Portugal
Contact:

Problem using custom events

Post by Lamego »

I have created a class which uses custom events to communicate with other classes on the program.
The code compiles and runs fine on Linux (wxGTK), however I get a linking error when building it on Windows:

On the Header file

Code: Select all

// Custome events go here

BEGIN_DECLARE_EVENT_TYPES()
    DECLARE_EVENT_TYPE(wxEVT_P_LIST_NEW, 7777)
    DECLARE_EVENT_TYPE(wxEVT_P_LIST_ITEM, 7778)
    DECLARE_EVENT_TYPE(wxEVT_P_JOIN_ROOM, 7779)
END_DECLARE_EVENT_TYPES()

#define EVT_P_LIST_NEW(id, fn) \
    DECLARE_EVENT_TABLE_ENTRY( \
        wxEVT_P_LIST_NEW, id, wxID_ANY, \
        (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
        (wxObject *) NULL \
    ),
    
#define EVT_P_LIST_ITEM(id, fn) \
    DECLARE_EVENT_TABLE_ENTRY( \
        wxEVT_P_LIST_ITEM, id, wxID_ANY, \
        (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
        (wxObject *) NULL \
    ),

#define EVT_P_JOIN_ROOM(id, fn) \
    DECLARE_EVENT_TABLE_ENTRY( \
        wxEVT_P_JOIN_ROOM, id, wxID_ANY, \
        (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
        (wxObject *) NULL \
    ),
On the Source file generating the events

Code: Select all

// Custome events definition

DEFINE_EVENT_TYPE(wxEVT_P_LIST_NEW)
DEFINE_EVENT_TYPE(wxEVT_P_LIST_ITEM)
DEFINE_EVENT_TYPE(wxEVT_P_JOIN_ROOM)
I get the following error:

Code: Select all

g++  -Wall -I/usr/local/lib/wx/include/msw-ansi-release-2.6 -I/usr/local/include/wx-2.6 -D__WXMSW__ -mthreads -DWXUSINGDLL=1 -DNO_GCC_PRAGMA    "-DIISLAND_PREFIX=\"/home/user/iisland\""   -o iisland.exe  iisland-MyApp.o iisland-Login.o iisland-PictureWindow.o iisland-hyperlink.o iisland-Protocol.o iisland-Utils.o iisland-SysTray.o iisland-RoomList.o iisland-RoomsList.o iisland-ChatCentral.o -L/usr/local/lib  -mthreads  -Wl,--subsystem,windows -mwindows -lwx_msw_xrc-2.6 -lwx_msw_qa-2.6 -lwx_msw_html-2.6 -lwx_msw_adv-2.6 -lwx_msw_core-2.6 -lwx_base_xml-2.6 -lwx_base_net-2.6 -lwx_base-2.6       
iisland-Protocol.o(.text+0x19b8):Protocol.cpp: undefined reference to `_imp__wxEVT_P_LIST_NEW'
iisland-Protocol.o(.text+0x1ac7):Protocol.cpp: undefined reference to `_imp__wxEVT_P_LIST_ITEM'
iisland-Protocol.o(.text+0x1e59):Protocol.cpp: undefined reference to `_imp__wxEVT_P_JOIN_ROOM'
iisland-RoomsList.o(.text+0x1366):RoomsList.cpp: undefined reference to `_imp__wxEVT_P_LIST_NEW'
iisland-RoomsList.o(.text+0x13a4):RoomsList.cpp: undefined reference to `_imp__wxEVT_P_LIST_ITEM'
collect2: ld returned 1 exit status
make[1]: *** [iisland.exe] Error 1
Do I need something special use custom events on Windows ?
wxMSW 2.6.3 - GCC 3.4.2 (MinGW/MSYS)
wxGTK 2.6.3 - GCC 4.02 (Ubuntu)
Code::Blocks Win/Lin
PTlink Tech Admin
PTlink Chat Software Lead Developer
http://software.pt-link.net
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

The code looks fine to me... perhaps you arn't compiling the relavant source file in by accident? Maybe it's in a dll?
[Mostly retired moderator, still check in to clean up some stuff]
Lamego
Earned some good credits
Earned some good credits
Posts: 101
Joined: Wed Jun 29, 2005 10:13 pm
Location: Portugal
Contact:

Resolved

Post by Lamego »

Hello,
I was compiling the code with MinGW GCC from a minimal shell, its the same process as compiling from Linux.
Meanwhile I did some research on google and found the following article:
http://www.xmule.ws/phpnuke/modules.php ... cle&sid=76

I added the following lines to the .h file:

Code: Select all

extern const wxEventType wxEVT_P_LIST_NEW;
extern const wxEVT_P_LIST_ITEM;
extern const wxEVT_P_JOIN_ROOM;
It compiles fine now, I believe its a compiler version related issue, I am using gcc4 on linux, gcc3 on mingw.

Thanks
wxMSW 2.6.3 - GCC 3.4.2 (MinGW/MSYS)
wxGTK 2.6.3 - GCC 4.02 (Ubuntu)
Code::Blocks Win/Lin
PTlink Tech Admin
PTlink Chat Software Lead Developer
http://software.pt-link.net
Post Reply