static and dynamic linking of an application

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
AnjaStemme
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 24, 2008 6:48 am

static and dynamic linking of an application

Post by AnjaStemme »

Hi,

I have a very basic question regarding the possibility to load dynamic applications (wxDynamicLibrary) into a statically linked wxWidgtes Application.

Is this possible?

If yes which (gcc) linker options are necessary on MAC and Windows?

Thanks a lot!

Anja
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre »

Is this possible?
Yes, for sure :-)
If yes which (gcc) linker options are necessary on MAC and Windows?
None

Simply load the dll and after, fetch the requested symbols.
AnjaStemme
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 24, 2008 6:48 am

Post by AnjaStemme »

briceandre wrote:
Is this possible?
Yes, for sure :-)
Well, on WinXP using wxPack it is - so far - not possible.
If I build the main application static and the loadable plugin static, the programm simply crashes when I try to load the plugin. Wenn I compile the plugin against the dll-version of wxWidgets, the load does not succeed.
briceandre wrote:
If yes which (gcc) linker options are necessary on MAC and Windows?
None

Simply load the dll and after, fetch the requested symbols.
Actually I thought that the behavior is quite as expected. If I build my application in a static way, all necessary functions are included. But if I build my plugin as well in a static way, the necessary functions would be included as well in the plugin and thus somehow "doubled". But if I build my plugin against the dll-version of wxwidgets, the plugin cannot find the necessary functions..

???

Thanks anyway
Anja
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre »

OK, but you did not mention that the dll you was planning to load was using wxWidgets :-)

AFAIK, a dll using wxWidgets cannot be linked statically to wxWidgets if you plan to use the same instance of wxWidgets in your main app. It should be feasible if you plan to use two distinct instances of wxWidgets, but I personnaly never tested and maybe you will have some troubles doing such a thing.

So, if you plan to use a dynamic version of wxWidgets, and plan to use the same instance in your main app, the only solutions (the simplest one and the best one, in my opinion) is to link everything as dynamic.
AnjaStemme
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 24, 2008 6:48 am

Post by AnjaStemme »

Yeah, thats why I finally linked both (main and plugin) against the dynamic dll wxWidgets versions.

BUT: Actually I preferred to have a static main application to distribute in order to avoid to supply individual widgets dlls to the end user; except for those I myself developed as loadable modules hence as extention plugins.

But obviously, this ist not possible?!

Anja
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre »

But obviously, this ist not possible?!
I am pretty sure this is feasible, even if I never tested it myself. But, you will have to :
1. Instanciate twice the wxWidgets library : once in your main app, and once in your dll. You will have to handle the initialisation in your dll by hand as you will not be allowed to use the IMPLEMENT_APP macro...
2. Embed the library in both your app and your dll (-> twice the size !)
3. No real communication between both libraries as they will be two distinct instances.

This is almost lke when someone develops a dll with gui features with wxWidgets for a gui main application that is not written with wxWidgets. Check on the forum. I remember a few weeks ago someone that was developping a plugin for a web browser.
AnjaStemme
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 24, 2008 6:48 am

Post by AnjaStemme »

Obviously things might vary from platform to platform...

So on Ubuntu I have no problems at all. I can link the plugin statically and load it into the (static linked) main application.

On Mac and on Windows XP the first call of to a wxWidgets method of the loaded (and statically linked) plugin leads to an segmentation fault and yet I do not understand why.

There are some threads around in the internet about statically linking of loadable moduls on Mac and Windows
which might lead to the idea that it should work (or not)...

Maybe the best thing is to give up and provide dynamic versions of the application for Mac and Windows. Nevertheless, thanks for the support and if there is anybody out there who already experienced the same problem and found a solution *please* let me know. This stuff is difficult to debug and so far I do not see my mistake
especially as it works perfect on Ubuntu (gcc) and I am using gcc on Mac and Windows as well.

Thanks again
Anja
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre »

On Mac and on Windows XP the first call of to a wxWidgets method of the loaded (and statically linked) plugin leads to an segmentation fault and yet I do not understand why.
If you statically linked wxWidgets with both the main app and your dll, you have two distinct instances of wxWidgets. Did you try to add initialisation of wxWidgets code in you dll ? That's probably the reason of your crash...
AnjaStemme
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Apr 24, 2008 6:48 am

Post by AnjaStemme »

briceandre wrote:
On Mac and on Windows XP the first call of to a wxWidgets method of the loaded (and statically linked) plugin leads to an segmentation fault and yet I do not understand why.
If you statically linked wxWidgets with both the main app and your dll, you have two distinct instances of wxWidgets. Did you try to add initialisation of wxWidgets code in you dll ? That's probably the reason of your crash...

I found the following information on the wxWidgets wiki page (http://wiki.wxwidgets.org/Creating_A_DL ... pplication) Sorry, maybe I should have stumbled about this page earlier but I really did not notice:
But please note that there are some issues when linking your DLL statically with wxWidgets. What i did is linking my DLL dynamically with wxWidgets, it seemed to solve all application initialization errors, so don't forget to define WXUSINGDLL in your compiler's settings, and compile your wxWidgets libs dynamically, at least for making wxWidgets DLLs.
and further more
The only problem that causes apps started from dll crash (when mouse enters wx window for first time), while apps started from static lib run fine, is bug [1]. This was later fixed in 2.9.0, most likely by changeset 56863 [2]. Before this fix, my workaround for 2.8.9 was to add "static" at the beginning of src/msw/window.cpp line 5179, "wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM);". This workaround was widely tested and used without any problems in 32bit and 64bit apps, however it's unsafe hack compared to proper fix in 2.9.0.
Hence I concluded that there is a principal problem at least with wxWidgets 2.8.x on Windows. As the plugin works fine on Ubuntu, I guess it does not make sense to look for any other workaround but deliver the dynamically linked application for Windows and Mac. Maybe the new version (2.9) of wxWidgets would solve the problems.

Anyway thanks for the help!!!

Anja
Post Reply