Problem with inlining and DLL

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
Giles
Knows some wx things
Knows some wx things
Posts: 31
Joined: Sat Jan 20, 2007 12:36 pm

Problem with inlining and DLL

Post by Giles » Sat Jan 20, 2007 2:29 pm

Hi,

I am trying to use wxWidget under MSW using DLL (at least for the development/test phase to speed up linking). I have been able to create my (tailored) DLL. I have succeeded to compile and link with it but the code is not consistent: for a same wx object it happens that some methods are inlined and some others are called in the DLL. This becomes a major problem as soon as the code refers to static variables because the executable has 2 different instances of these variables: one in the DLL and one in the EXE. The inlined code refers to the EXE variable, the DLL code refers to DLL variable.

I found in wxWidget code a clue that shows that I am not the first one to have this problem (string.h line 230):

Code: Select all

  // VC++ free must take place in same DLL as allocation when using non dll
  // run-time library (e.g. Multithreaded instead of Multithreaded DLL)
#if defined(__VISUALC__) && defined(_MT) && !defined(_DLL)
  void  Unlock() { if ( !IsEmpty() && --nRefs == 0) Free();  }
  // we must not inline deallocation since allocation is not inlined
  void  Free();
#else
  void  Unlock() { if ( !IsEmpty() && --nRefs == 0) free(this);  }
#endif
But it seems that only VC++ should have the problem. I use gcc and this does not work either:

Code: Select all

delete new wsString(_T("x"));
At the first line of the program is enough to crash it (may not happen with any program as deallocation errors don't create reproducible crashes).

So I tried to modify my DLL (and my code) by setting USE_STL so this code is no longer used and the STL is used instead. This is better because the line above is executed correctly.
But I get the same anomaly for many other wx objects that are not backup in the STL!

How should this mix of inline and DLL for a single object be avoided when using wxWidget DLL with gcc/MinGW? Note that the question is not specific to wxWidget, I would have the same problem if I tried to create a DLL containing C++ classes with any inlinable code.
Using Gcc of MinGW 5.1.2 + WxWidget 2.8.7 under XP

Post Reply