dlls, dsos, Python, linking

Not specifically Panda, but some general questions on dlls, dsos, Python, linkings.

The underlying theme is: what are the options for building add-on C/C++ libraries for Panda?

My impressions are:

Using Python as a link engine:

  • if the plug-in directly calls the Panda API, it has to link directly with libpanda.dll, either via an import library, or at runtime via LoadLibrary
  • its not sufficient simply for Python to import both the Panda dll and the new library dll

Multiple links to one dll:

  • Lets say we have two dlls: child.dll and parent.dll. Parent is linked to child.dll, ie its linked to the child.lib import library, and loads child.dll automatically at runtime
  • if we have a single process that links with both child.dll and parent.dll (links to their import libraries), then:
  • only one copy of child.dll is in memory (this much is obvious)
  • only one copy of child.dll’s static data is in memory?
  • the dll’s initialization routines are only called once?

The last two appear a posteriorae to be the case on Windows. To what extent are they always the case? More importantly: to what extent are they the case on other platforms?

Back to the original theme, it looks like we can actually get our add-on library to be a new dll that simply links with libpanda.dll and libpandaexpress.dll?

The application would likely load all of libpanda.dll, libpandaexpress.dll, libframework.dll and libmynewlibrary.dll at runtime. However, only one copy of libpanda.dll and libpandaexpress.dll 's static data would exist. The linking is basically essentially just allowing the application to use the different APIs of each?

Is this a fair impression?

Hugh

Yes, this sounds exactly right.

As far as I know, all modern operating systems support shared libraries in this sensible way, although there is that issue with templates and DLL’s on Windows. I also heard about a problem with OSX’s linker and static init across shared libraries, but that was a while back, and Apple did promise to fix the linker–maybe they have by now.

David