[CMake] Creating libraries (DLL) in windows
Leopold Palomo Avellaneda
leo at alaxarxa.net
Fri Aug 1 18:41:11 EDT 2008
Mike,
yes it helps, and a lot!!!!
> Now, in the class declaration for each of your classes add the
> definition:
I understand that you have to add:
class MYLIB_EXPORT MyClass
for all the classes,
but also for the structs , and functions?
Leo
A Dissabte 02 Agost 2008, Mike Jackson va escriure:
> Well, basically, Cmake will _help_ you create your library BUT there
> is some work that you need to add to your project.
>
> Say your library is named "mylib" and Your project name is MyLib.
>
> When you do
> Add_library(MyLib SHARED ${Sources}) cmake will automatically add a
> definition "MyLib_EXPORT" to the compiler invocation on windows.
> In my example you will also need to define SET (BUILD_SHARED_LIBS
> TRUE) in your cmakelists.txt file.
>
> Now to use that bit of information you need to have something like
> the following in a header file that gets included by all your classes:
>
> #if defined (WIN32) && defined (BUILD_SHARED_LIBS)
> #if defined (_MSC_VER)
> #pragma warning(disable: 4251)
> #endif
> #if defined(MyLib_EXPORT)
> #define MYLIB_EXPORT __declspec(dllexport)
> #else
> #define MYLIB_EXPORT __declspec(dllimport)
> #endif
> #else
> #define MYLIB_EXPORT
> #endif
>
>
> Now, in the class declaration for each of your classes add the
> definition:
>
> class MYLIB_EXPORT MyClass
> {
>
> };
>
> So what happens when all of this is implemented is that on non
> windows platforms the MYLIB_EXPORT is defined to NOTHING and has not
> affect. On Windows MYLIB_EXPORT will get defined to __declspec
> (dllexport) when you actually compile the library or __declspec
> (dllimport) when the library is being linked to by another library or
> executable.
>
> I hope all this helps.
>
> Take a look at <http://titanium.imts.us/viewvc/Task_7/MXADataModel/>
> then src/Common/DLLExport.h for a working example.
--
--
Linux User 152692
PGP: 0xF944807E
Catalonia
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080802/996c03d8/attachment.pgp>
More information about the CMake
mailing list