I have done some research concerning dynamic link libraries (dll) under windows, which means I googlet
One result has quite an impact on our code: If you want to use a dll, you need to have a *.lib file, that contains all the symbols (eg. variables and functions). And in order to create such a static library file, you need to specify the necessary function with an attribute in the code. Fortunately, it is sufficient for the class definition:
class __declspec( dllexport) DoomsdayDevice {
};
But: Once you would like to use such a function, you need to import it:
class __declspec (dllimport) DoomsdayDevice {
};
--> Hence we need to define a preprocessor symbol to do that job, since we can include the same header file in the library, as well as in a program, where we want to use the library.
The Ogre developers of course had the same problem. Their solution is to always include a header file: "OgrePrerequisites.h", which includes "Platform.h", where the export/import symbol is defined.
This brings up another problem: Including header files in header files is a bad idea, unless you can't help it (e.g. you want to inherit from a class). The problem already came up in the network library: If you use it, you need to include its header files, and these contain files from the boost and enet library, which you don't want to link as well, since they're already linked to the network library.
So, in header files it is sufficient to have a simple prototype for each class used in the header file, if only used as a pointer:
class DoomsdayDevice;
class AnotherDevice;
etc.
Now, in this prerequisites file, all these prototypes are stored in for the entire library.
This concept also saves a lot of compile time.
--> Every subproject with its own library needs a "name_prerequisites.h" and a "name_platform.h" header file, or however you want to call the files, just be consistent.