> Well, then just use add_definitions(-DIMPORT_X_DLL). If -DEXPORT_X_DLL
> is present, it will override your export/import header definitions for
> the import case, and everything should be fine.

Not sure what you mean by override. If both symbols are defined, MTK_COMMON will be defined as __declspec(dllexport) and not __declspec(dllimport), since my headers have #elif, #not elses. Using add_definitions makes sense however. I just started using CMake two days ago and was not aware of that command.

>> CMake will only
>>> add the DEFINE_SYMBOL when *building* the specified target, and
>>> otherwise just leave it away.
>
> When CMake invokes the compiler to *build* the DLL it adds
> -DEXPORT_X_DLL. If the DLL is being *used* it doesn't do anything.

That is the problem. When you say it does not do anything,(in the 'use' case) it is in fact defining the dllimport flag (after your #else).

The way my define structure looks, that does not happen.

>>> 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
No, I'm not doing that in my code. But I tried it, and together with target_link_library everything compiles fine. In my opinion, however, those #defines gives you something defined, without defining anything.. that is a little too clever in my opinion. But practical.

>> I'll try to see if that works. Right now I do have an exporter/importer
>> header and it is more complex and looks like (for a target "COMMON"):
>> #if defined(EXPORT_COMMON_DLL)
>>      #define MTK_COMMON __declspec(dllexport)
>> #elif defined(IMPORT_COMMON_DLL)
>>      #define MTK_COMMON __declspec(dllimport)
>> #elif defined(EXPORT_COMMON_PKG)
>>      #define MTK_COMMON __declspec(package)
>> #elif defined(IMPORT_COMMON_PKG)
>>      #define MTK_COMMON __declspec(package)
>> #else
>>      #define MTK_COMMON
>> #endif
>
> Is this for embarcadero c++? in which case do you define
> EXPORT_COMMON_DLL, and when do you use EXPORT_COMMON_PKG?

The package spec is a embarcadero flavor of a dll (that can be installed in the IDE). That is why I need elseifs, and not just an else.


>
>
> To help you more, I would need to understand __declspec(package). The
> Embarcadero docs didn't really help me grasp its use...

The main difference compared to a regular DLL It gives the dll a handle to the main application I think. Embarcadero packages has .bpl as extension. It has nothing to do with why my dll could not get symbols from another dll.

Well, seems that the target_link_libraries and the add_definitions did it!

Thanks for your feedback!
Totte
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to