Linking errors with a DLL that uses WX

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
eventhorizon5
In need of some credit
In need of some credit
Posts: 6
Joined: Sat Sep 02, 2017 4:05 am

Linking errors with a DLL that uses WX

Post by eventhorizon5 »

Hi, I'm having problems with linking an app that uses wxWidgets. It builds and links fine on other platforms (both Linux and MacOS), but fails on Windows (Visual C++). I'm assuming the preprocessor settings are all correct, and everything else seems fine. WX was built as a DLL, in Unicode.

The project I'm building is called wxSF, and is a 2D drawing library. The preprocessor definitions are:
WIN32;NDEBUG;_WINDOWS;_PRECOMP;wxUSE_GUI=1;WXMAKINGDLL_WXSF=1;UNICODE;_UNICODE;
(the WXSF one is a custom one for the library). I tried also setting wxUSINGDLL, but that resulted in more errors.
Linked libraries are:
wxbase30u.lib
wxmsw30u_core.lib
wxbase30u_xml.lib

I've attached the build errors. I noticed that some debugging functions are listed, and there doesn't seem to be a reason for that. Some "const char *" entries are there, even though it's using unicode.
Attachments
output.txt
(46.41 KiB) Downloaded 116 times
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Linking errors with a DLL that uses WX

Post by eranon »

Hello, I always use static linking against wxWidgets and I go with GCC, but here my two cents:

The usual definitions I pass to the compiler, talking abour RELEASE target, are those below; maybe you can transpose for MSVC:
__GNUWIN32__
__WXMSW__
wxUSE_UNICODE
WX_PRECOMP
NDEBUG
wxDEBUG_LEVEL=0

wxDEBUG_LEVEL has to be forced to zero (0) in wxWidgets's setup.h (or at call) to strip out all debug info in wxWidgets, even if you specified BUILD=release and DEBUG_FLAG=0.

The documentation about VC++ and wxWidgets is here: https://wiki.wxwidgets.org/Microsoft_Vi ... B%2B_Guide. It sounds like the right symbol is WXUSINGDLL rather than WXMAKINGDLL.

And, of course, preferably, you must use the same flags for you app than the ones used for wxWidgets compiling.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
eventhorizon5
In need of some credit
In need of some credit
Posts: 6
Joined: Sat Sep 02, 2017 4:05 am

Re: Linking errors with a DLL that uses WX

Post by eventhorizon5 »

I added some of those preprocessor options, and the error count decreased slightly from 50 to 48. I tried building WX as static, and it still has the same errors. Some of the functions are part of the WX core, so that's why I'm confused by this problem.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Linking errors with a DLL that uses WX

Post by doublemax »

When you tried WXUSINGDLL, did you use it instead of WXMAKINGDLL_WXSF or additionally? It should be additionally.

Even if you were getting more errors, were the errors different?
Use the source, Luke!
eventhorizon5
In need of some credit
In need of some credit
Posts: 6
Joined: Sat Sep 02, 2017 4:05 am

Re: Linking errors with a DLL that uses WX

Post by eventhorizon5 »

I tried building WX as a static library, and the errors disappeared, but there were a lot of new linking errors - adding some libraries like the wxpng and wxzlib libraries decreased the count somewhat.

When building with WXMAKINGDLL_WXSF=1 (which sets the DLL export type of the wxSF library) and WXUSINGDLL=1, I get "inconsistent DLL linkage" errors. Maybe the problem is related to how this library is exporting it's functions.

Here's the wxSF library's function export defs:

Code: Select all

#ifdef USING_SOURCE_SF
	#define WXDLLIMPEXP_SF
    #define WXDLLIMPEXP_DATA_SF(type) type
#elif defined( LIB_USINGDLL )
    #define WXDLLIMPEXP_SF
    #define WXDLLIMPEXP_DATA_SF(type)
#elif defined( WXMAKINGDLL_WXSF )
    #define WXDLLIMPEXP_SF WXEXPORT
    #define WXDLLIMPEXP_DATA_SF(type) WXEXPORT type
#elif defined(WXUSINGDLL)
    #define WXDLLIMPEXP_SF WXIMPORT
    #define WXDLLIMPEXP_DATA_SF(type) WXIMPORT type
#else // not making nor using DLL
    #define WXDLLIMPEXP_SF
    #define WXDLLIMPEXP_DATA_SF(type) type
#endif
eventhorizon5
In need of some credit
In need of some credit
Posts: 6
Joined: Sat Sep 02, 2017 4:05 am

Re: Linking errors with a DLL that uses WX

Post by eventhorizon5 »

Update - I tried building wxSF as a static library, and it works, along with the linking with the parent exe file. So the problem should be a DLL exporting/importing issue with the wxSF library.
eventhorizon5
In need of some credit
In need of some credit
Posts: 6
Joined: Sat Sep 02, 2017 4:05 am

Re: Linking errors with a DLL that uses WX

Post by eventhorizon5 »

I found the problems. It turns out that the wxSF library has an additional import/export definition called WXMAKINGDLL_WXXS that needed to be set.
Post Reply