Microsoft 开发人员网络 > 论坛主页 > Visual C++ General > Using old DLL files built in VS2003 with new projects in VS2008
提出问题提出问题
 

已答复Using old DLL files built in VS2003 with new projects in VS2008

  • 2009年7月2日 13:15Sadik AKBULUT 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    I am using some DLL files built with VS2003 in my C++ project. When I was using VS2003 there were no problems. But I've recently upgraded to VS2008 and now I'm getting some linker errors about unresolved external symbols (which are supposed to exist in these DLL files).

    After some search on the internet, I've come up with the following page.
    http://msdn.microsoft.com/en-us/library/tyx5b79y(VS.71).aspx


    This seems to be my problem but with a difference. I cannot rebuild the DLL files which export these symbols. I have to tell the linker to use the correct symbol (old-style) when linking my project to the DLL file.

    I've no chance to rebuild these DLL files with VS2008 and I don't want to downgrade to VS2003.

    Is there any solution (like some linker options) to this problem?

答案

  • 2009年7月2日 22:10Giovanni DicanioMVP用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    If you have a DLL with a C++ interface, you should use this DLL only with the same compiler that you used to build it.
    For example, if your DLL has STL classes like std::vector at his interface, std::vector implementation in VC2003 can be different from std::vector implementation in VC2008, so even if the names of these classes are the same, these classes are actually different "guys" (e.g. they could have different internal implementation).

    My first suggestion to you would be to recompile your C++-interface DLL with VS2008.

    If you can't do it (e.g. you don't have the DLL source code), you may want to build a COM wrapper around your VC2003 DLL. COM is a very robust (but complex...) technology to shield against the particular language or compiler you used to build the COM module. e.g. you could use a COM component written in VC6 with VC8!
    So, thanks to a proper COM wrapper around your VC2003 C++ DLL, you could use its functionalities from VC2008.

    HTH,
    Giovanni

全部回复

  • 2009年7月2日 13:24nobugzMVP, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    The article you linked talks about breaking behavior in VS2003 from VS2002.  That cannot match your problem.  Document your problem better, post the linker errors you see and the declarations of the identifiers it is looking for.

    Hans Passant.
  • 2009年7月2日 22:10Giovanni DicanioMVP用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    If you have a DLL with a C++ interface, you should use this DLL only with the same compiler that you used to build it.
    For example, if your DLL has STL classes like std::vector at his interface, std::vector implementation in VC2003 can be different from std::vector implementation in VC2008, so even if the names of these classes are the same, these classes are actually different "guys" (e.g. they could have different internal implementation).

    My first suggestion to you would be to recompile your C++-interface DLL with VS2008.

    If you can't do it (e.g. you don't have the DLL source code), you may want to build a COM wrapper around your VC2003 DLL. COM is a very robust (but complex...) technology to shield against the particular language or compiler you used to build the COM module. e.g. you could use a COM component written in VC6 with VC8!
    So, thanks to a proper COM wrapper around your VC2003 C++ DLL, you could use its functionalities from VC2008.

    HTH,
    Giovanni