In my application I have 3 major parts:
- Exe : an executable file
- Lib_A : a library contains a singleton class and a base class for some calculations to be use in singleton
class - Lib_B : a library contains a number of classes derived from the base in Lib_A
The reason that I have the derived classes in Lib_B is, I would like to compile the Lib_B at runtime from Exe. I need to generate derived classes during the calculations without terminating the whole system. This is too important for me. That means initially I may have say Lib_B1 dynamically loaded, also I may compile other versions of Lib_B as Lib_B2, Lib_B3, Lib_B4 etc. and load them dynamically too. All Lib_Bx libraries will have entry point functions to export the classes in them.
So taking the following facts into account :
- At runtime there will be various number of files sharing the same Lib_A.
- The application must run in Windows and Linux. So partial cross-platformness is an issue.
- I am going to use some libraries like TBB, Boost, Qt which may have their own libraries like tbb.dll etc.
What are the pros and cons of statically or dynamically linking of Lib_A against both Exe and Lib_Bx’s? How can perfomance, size of system etc. be affected? Are there any dangerous or difficult situations I may encouter besides for each OS I need to use the same compiler for Exe, Lib_A and Lib_Bx’s.
The design of the whole system is a very hard problem for me, so any comments will be appreciated.
Thanks very much.
From what I understand of your project description, you should link Lib_A dynamically : if you link Lib_A statically to each of your Lib_Bx shared libraries, you will duplicate x times the Lib_A code and static variables.
Say, if you have a class in Lib_A, that have the form :
instance_countwill be duplicated in all your shared libraries, thus make it impossible forBaseKlassto count its instances.You could possibly be bitten by more subtle problems with virtual tables, or RTTI (dynamic_cast), etc.
You should have a look at this boost.python document that describes problems related to what I mentionned.
Boost.python allows to create python modules (dynamic libraries) that are to be loaded in the same process. Each python module created with boost.python, if they are to communicate together at the c++ level such as deriving a class B in a module from a class A in another module, is supposed to link dynamically with boost.python lib to avoid problems.