linking errors with DLL linked to static libraries

Discussion in 'C++' started by mijal, Aug 23, 2007.

  1. mijal

    mijal New Member

    Joined:
    Jul 13, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have a class located in a stored library. I then linked the library to a DLL. If I call the class like this:

    example:
    Code:
    // sample of class defined in library
     class myExample
     { ..... };
    
    // include header file in DLL 
    // if i use this
        myExample newInstance;   // results to linker problems
    
    // but if i use it this way
       myExample *newInstance;  
       newInstance = new myExample() // linker problems
    
    
    There seems to be redefinition of the functions/declarations found in libcpmtd.lib and msvcprtd.lib. I'm getting LNK2005 errors. It is saying that those declarations was already defined in the static library.
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    That could happen if you link to the .h file more than once without you having them opt out with the pre-processor directives or it could happen that you include the .cpp file instead of .h file.
     
  3. mijal

    mijal New Member

    Joined:
    Jul 13, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    ok thanks.
    But is it really ok to use static libraries and use them in dlls?
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Yes thats fine.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice