添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
I'm trying to build an executable (exe) and a dynamic-link library (dll) using wxWidgets in a Windows C++ project. In the dll project, I have defined an event type using wxDECLARE_EVENT and wxDEFINE_EVENT. However, when I try to use the event type defined in the dll from the exe, it results in an unresolved link error.
Both projects are CMake projects, and for the dll project, I have the following settings:

Code: Select all

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(targetname SHARED)
The same code builds successfully on Linux.
Could you please help me understand why the event type defined in the dll is causing an unresolved link error?

Code: Select all

wxDECLARE_EVENT( myEventType, myEvent );

Code: Select all

wxDECLARE_EXPORTED_EVENT( WXEXPORT, myEventType, myEvent );
, imitating the code in wx/event.h, but it didn't work as expected.
#define HOGE __declspec(dllimport) #endif // MY_DLL_BUILDING HOGE wxDECLARE_EVENT( myEventType, myEvent ); When I tried writing the code in this way, the build was successful and it worked. However, I received a warning saying "inconsistent linkage". I don't think it's correct to write it this way in each header file.
According to event.h, is this supposed to be used as WXDLLIMPEXP_BASE before wxNewEventType()? WXDLLIMPEXP_BASE appears to be determined based on WXMAKINGDLL_BASE and WXUSINGDLL in dlimpexp.h. How should these be configured? Are you trying to add new event to the library or your code?
Please check the documentation - specifically event handling overview and the event sample on how to make the new event.
Thank you.
Thanks for the reply.
I am trying to define events and event types in my own library and use them from different projects.
If I make the library a static library, there is no problem, but if I make it a dynamic library, the link does not resolve.
I think it is because the event types are not exported to the dll, as I was able to build it by adding "__declspec(dllexport)" etc.
I could not find any information about DLL in the event documentation.
In the dll sample I added "__declspec(dllexport)" etc. to the function, is this the correct way to do it for event types as well?
Is there a better way using wxDECLARE_EXPORTED_EVENT, WXEXPORT, WXIMPORT, etc.?
  • ↳   Compiler / Linking / IDE Related
  • ↳   Platform Related Issues
  • wxWidgets Specialized Forums
  • ↳   wxDev-C++
  • ↳   wx.NET
  • ↳   The Code Dump
  • ↳   wxCode
  • General Forums
  • ↳   General Development
  • ↳   Announcements and Discoveries
  • ↳   Open Discussion
  • ↳   Database Related
  • International Forums
  • ↳   wxWidgets Development (French)
  • ↳   wxWidgets Development (Chinese)
  • ↳   wxWidgets Development (Russian)
  •