KDE_EXPORT in kdelibs and winposix

Brad King brad.king at kitware.com
Thu Feb 9 20:15:33 CET 2006


Hello,

Currently KDE_EXPORT is defined both by kdemacros.h and 
winposix_export.h.  Also, KDE_IMPORT is defined both by 
kdelibs_export_win.h and winposix_export.h.  Their definitions are 
different:

// kdemacros.h
#ifdef __KDE_HAVE_GCC_VISIBILITY
#define KDE_NO_EXPORT __attribute__ ((visibility("hidden")))
#define KDE_EXPORT __attribute__ ((visibility("default")))
#elif defined(_WIN32) || defined(_WIN64)
#define KDE_NO_EXPORT
#define KDE_EXPORT __declspec(dllexport)
#else
#define KDE_NO_EXPORT
#define KDE_EXPORT
#endif

// winposix_export.h
#ifdef _MSC_VER
#define KDE_EXPORT __declspec(dllexport)
#define KDE_IMPORT __declspec(dllimport)
#else
#define KDE_EXPORT
#define KDE_IMPORT
#endif

// kdelibs_export_win.h
#if defined(__MINGW32__)
# define KDE_IMPORT
#else
# define KDE_IMPORT __declspec(dllimport)
#endif

This results in a redefinition of KDE_EXPORT for many translation units 
on Windows.  Many DLL linking problems result when I try to build 
kdelibs, particularly on MinGW.

I suggest that the winposix_export.h versions be renamed to 
WINPOSX_EXPORT and WINPOSX_IMPORT since they are supposed to be 
separated from kdelibs anyway.  They are only used for symbols in 
kdewin32 so this should be okay: KDEWIN32_EXPORT would map to 
WINPOSX_EXPORT or WINPOSX_IMPORT depending on whether the library is 
being built or used.

I also propose removing KDEWIN32_EXPORT from kdelibs_export_win.h 
because it should be defined only in winposix_export.h.  Since 
winposix_export.h is included directly or indirectly by all headers in 
kdewin32 this should work well.

The file win/include/mingw/sys/types.h does this:

#ifdef __cplusplus
#include <winposix_export.h>
#else
#define KDEWIN32_EXPORT
#endif

but it looks like it should just be

#include <winposix_export.h>

Finally, I think __declspec(dllimport) should be used on MinGW just like 
other windows platforms.  The auto-import feature does not work well for 
data symbols such as vtables.  See the man-page of ld in MinGW or cygwin 
and read the enable-auto-import flag documentation for details.

Comments?
-Brad


More information about the Kde-buildsystem mailing list