[CMake] import/export and DLL's

Michael Wild themiwi at gmail.com
Tue Dec 6 03:53:53 EST 2011


On 12/06/2011 09:47 AM, Totte Karlsson wrote:
> Hi, I have a project where several DLL's are to be built, say A, B
> and C. B needs to import functions/classes from A, and C need to
> import functions from both A and B. In each library, a flag is
> defined for exporting or importing, i.e. __declspec(dllexport) or
> __declspec(import)
> 
> The build order is first A, then B and then C. I have defined build
> flags in CMakeList.txt files as, in A for example 
> SET_TARGET_PROPERTIES (${target} PROPERTIES DEFINE_SYMBOL 
> "EXPORT_A_DLL")
> 
> in B SET_TARGET_PROPERTIES (${target} PROPERTIES DEFINE_SYMBOL 
> "EXPORT_B_DLL") SET_TARGET_PROPERTIES (${target} PROPERTIES
> DEFINE_SYMBOL "IMPORT_A_DLL")
> 
> and in C SET_TARGET_PROPERTIES (${target} PROPERTIES DEFINE_SYMBOL 
> "EXPORT_C_DLL") SET_TARGET_PROPERTIES (${target} PROPERTIES
> DEFINE_SYMBOL "IMPORT_A_DLL") SET_TARGET_PROPERTIES (${target}
> PROPERTIES DEFINE_SYMBOL "IMPORT_B_DLL")
> 
> The only dll that seem to be built OK is A. In B and C, nothing seem
> to be exported. Any tips on how to deal with this? I am using
> CodeGear platform. Building static libs works fine.
> 
> -totte
> 

You misunderstand and misuse the DEFINE_SYMBOL property. All the
IMPORT_X_DLL symbols are wrong, you have to remove them. CMake will only
add the DEFINE_SYMBOL when *building* the specified target, and
otherwise just leave it away.

So, in your code you do something like this:

#ifdef EXPORT_A_DLL
#define A_API __declspec(dllexport)
#else
#define A_API __declspec(dllimport)
#endif

For B and C the definitions are analogous.

HTH

Michael


More information about the CMake mailing list