3

I am working on a project (cross-platform, but only Windows matters in this case) that creates a lot of shared libraries (which are somewhat dependent of each other). All the header files that declare functions or structures/classes/enums/etc. are found in a separate /include folder but the source files are grouped into modules.

I have created a macro for _declspec import/export but my question is this:

Should I have a different preprocessor directive that triggers the export version for each library? Since the libraries can use headers that belong to other libraries, is it important that those symbols are seen as import?

From what I have tested on a mock project, you can have them all as export symbols and they still work, but is this good practice?

Thank you.

tatones
  • 81
  • 4

1 Answers1

0

you should create a macro to declare export on class/function you wish to export out from your library. all include headers (of your dependency) should be declared as Import. i don't follow you how exporting all everytime is working for you (it shouldn't).

here is an example -

on the 1st library define in the .h file. in the project file define a preprocessor __your_module_name>_DLL__

library 1 header file:

#ifdef __<your_module_name>_DLL__
#define <your_module_name>_EXPORT __declspec(dllexport)
#else
#define <your_module_name>_EXPORT __declspec(dllimport)
#endif

class <your_module_name>_EXPORT someName
{
    ....
}

on 2nd library if it imports the 1st library header file and assuming __<your_module_name>_DLL__ preprocess is not define on its project file, the someName class will be imported rather than exported.

this will allow you to use the cross dependencies correctly during compilation.

NirMH
  • 4,769
  • 3
  • 44
  • 69