Menu

use of dllexport in win32

2000-12-24
2001-08-30
  • Gary Bartlett

    Gary Bartlett - 2000-12-24

    I noticed that the win32 version of config.h defines __EXPORT as __declspec(dllexport).  This is great for compiling the Common C++ library, but when trying to use/import the library in our own programs it causes the entire library to be re-exported from our programs too.  The usual way of handling this seems to be with something like

    #ifdef CXX_EXPORTS
    #define    __EXPORT    __declspec(dllexport)
    #else
    #define    __EXPORT    __declspec(dllimport)
    #endif

    and then CXX_EXPORTS is added to the project to build the library and omitted from projects that just import it.

    I'm new to Common C++ and SourceForge, so any guidance on how things like this should be reported would be appreciated.

    Thanks,
    Gary

     
    • David Sugar

      David Sugar - 2000-12-26

      Hmm...let me think about this one...__EXPORT then isn't really a good name for this, since it can also be an "import", by default...

       
      • Kevin Walsh

        Kevin Walsh - 2001-02-06

        A typical msdev template would say something along the following:

        #define __EXPORT __declspec(dllexport)
        #define __IMPORT __declspec(dllimport)
        // on unix, just declare empty __EXPORT and __IMPORT macros

        // then do
        #ifdef CCXX_EXPORTS // define in makefile or project
        #define CCXX_API __EXPORT
        #else
        #define CCXX_API __IMPORT
        #endif

        #ifdef CCIO_EXPORTS
        #define CCIO_API __EXPORT
        #else
        #define CCIO_API __IMPORT
        #endif
        // etc.

        This also makes it easy to figure out which classes belong in each of the 3 dlls.  On win32, you really want to __IMPORT the ccxx and ccio classes when __EXPORTing the ccstd classes, and so on.  This is pretty clear if you use CCXX_API or CCIO_API or whatnot.

        -kevin

         
    • Frediano Ziglio

      Frediano Ziglio - 2001-08-30

      Mm... there are no need to use code such

      #ifdef CCXX_EXPORTS // define in makefile or project
      #define CCXX_API __EXPORT
      #else
      #define CCXX_API __IMPORT
      #endif

      config.h for default declare __EXPORT as __declspec(import). This is overwritten in export.h (included in all implementation, not headers).

      I have changed export declaration with 4 macro:
      CCXX_EXPORT()
      CCXX_MEMBER()
      CCXX_MEMBER_EXPORT()
      CCXX_CLASS_EXPORT
      (i will extend use for specify different linkage explicitly)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.