> > #if BUILDING_LIBFOO && HAVE_VISIBILITY > > #define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default"))) > > #elif BUILDING_LIBFOO && defined _MSC_VER > > #define LIBFOO_DLL_EXPORTED __declspec(dllexport) > > #elif defined _MSC_VER > > #define LIBFOO_DLL_EXPORTED __declspec(dllimport) > > #else > > #define LIBFOO_DLL_EXPORTED > > #endif > > > > Trouble is, this doesn't handle the case where I'm > > building a static lib using MS tools. In that case I > > (think I) want the macro to be empty. > > libtool should be adding -DPIC only for the non-static > objects, that should allow you to distinguish between that > and the objects that are used for the DLL.
Having LIBFOO_DLL_EXPORTED depend on whether PIC is defined works for building libfoo itself -- the shared library have exports decorated with __declspec(dllexport) and for the static library, LIBFOO_DLL_EXPORTED is empty. My macros look like this now: #if BUILDING_LIBFOO && HAVE_VISIBILITY # define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default"))) #elif defined _MSC_VER # if BUILDING_LIBFOO && defined(PIC) # define LIBFOO_DLL_EXPORTED __declspec(dllexport) # elif !defined(BUILDING_LIBFOO) # define LIBFOO_DLL_EXPORTED __declspec(dllimport) # else # define LIBFOO_DLL_EXPORTED # endif #else # define LIBFOO_DLL_EXPORTED #endif For the _MSC_VER case, I read the three alternatives like this: 1. If building a shared version of libfoo: __declspec(dllexport) 2. else if using libfoo (shared or static): __declspec(dllimport) 3. else (i.e. building a static version of utils): nothing but it turns out this is insufficient. #1 and #3 are correct, but to make LIBFOO_DLL_EXPORTED correct all the time I need to split #2 into separate cases. __declspec(dllimport) is correct when using a shared libfoo, but when using a static libfoo, I need LIBFOO_DLL_EXPORTED to be empty. I'm loving M$ at the moment. One way to resolve this is to provide some extra (aka project-specific) option at configure time so users can specify that they want static or shared. Then I can use that in my preprocessor logic and pass -all-static or -static or -static-libtool-libs (haven't figured out which yet) in blah_LDFLAGS. Working on this now. Curious what people think of this, and if there's a better way that I'm missing (other than ditching MS which unfortunately isn't an option at the moment). Thanks. -DB _______________________________________________ http://lists.gnu.org/mailman/listinfo/libtool