exporting C++ classes from a DLL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alfonso Morra

    #1

    exporting C++ classes from a DLL

    I have a class declared as ff:

    class __declspec(dlle xport) A {
    public:
    A() ;
    A(const A&)
    A& operator=(const A&) ;
    ~A() ;

    void doThis(void) ;
    void doThat(void) ;

    private:
    std::string s ;
    std::vector< <std::pair> > vp ;
    ......
    };


    When I compile the code, the compiler generates several warnings such as:

    warning C4251: 'A::s' : class 'std::basic_str ing<_Elem,_Trai ts,_Ax>'
    needs to have dll-interface to be used by clients of class 'A'
    with
    [
    _Elem=char,
    _Traits=std::ch ar_traits<char> ,
    _Ax=std::alloca tor<char>
    ]

    etc. Why do I have to export private variables (is that what the warning
    message is instructing me to do?)

    Despite the warnings, the code builds and the dll is built. When I use
    the dll in another project, problems (unsuprisingly) arise but they are
    of a slightly different kind. One of the class methods is anoverloaded
    function template method. This does not seem to be exported and I am
    getting a link error when I try to link to A.lib so I can create a
    project that uses classes exported by A.dll

    Any pointers will be appreciated. Tks

  • Nishant Sivakumar

    #2
    Re: exporting C++ classes from a DLL

    See : http://support.microsoft.com/kb/q168958/

    --
    Regards,
    Nish [VC++ MVP]
    Nish’s thoughts on technology leadership, cloud architecture, and APIs, among other things




    "Alfonso Morra" <sweet-science@the-ring.com> wrote in message
    news:dbj2nu$1oj $1@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...[color=blue]
    >I have a class declared as ff:
    >
    > class __declspec(dlle xport) A {
    > public:
    > A() ;
    > A(const A&)
    > A& operator=(const A&) ;
    > ~A() ;
    >
    > void doThis(void) ;
    > void doThat(void) ;
    >
    > private:
    > std::string s ;
    > std::vector< <std::pair> > vp ;
    > ......
    > };
    >
    >
    > When I compile the code, the compiler generates several warnings such as:
    >
    > warning C4251: 'A::s' : class 'std::basic_str ing<_Elem,_Trai ts,_Ax>' needs
    > to have dll-interface to be used by clients of class 'A'
    > with
    > [
    > _Elem=char,
    > _Traits=std::ch ar_traits<char> ,
    > _Ax=std::alloca tor<char>
    > ]
    >
    > etc. Why do I have to export private variables (is that what the warning
    > message is instructing me to do?)
    >
    > Despite the warnings, the code builds and the dll is built. When I use the
    > dll in another project, problems (unsuprisingly) arise but they are of a
    > slightly different kind. One of the class methods is anoverloaded function
    > template method. This does not seem to be exported and I am getting a link
    > error when I try to link to A.lib so I can create a project that uses
    > classes exported by A.dll
    >
    > Any pointers will be appreciated. Tks
    >[/color]


    Comment

    Working...