开发者

Link error after update from VS2008 to VS2010

Today I encountered a linking problem after updating the VS version from 2008 to 2010, the error is something like this:

error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::assign(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z)

error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) referenced in function "protected: bool __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Grow(unsigned int,bool)" (?_Grow@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IAE_NI_N@Z)

I have googled this issue on the web, and found a similar post in this address : http://social.msdn.microsoft.com/Forums/en/vcg开发者_运维知识库eneral/thread/5ac28a31-3339-4db1-90f4-68edad360309

But none of these answers can solve my problem. Could anyone give me some tips on how to solve this issue?

Thanks a lot for the help!


The problem is most likely that one of the libraries your .exe is linking against was built with a previous version of Visual Studio. Because this "other" library was compiled with a previous version of VS, it is looking for the previous versions of the functions _XRan and _XLen in the VS2010 C runtime. MS has changed them (yet again) and they old function signatures don't exist in the VS2010 runtime.

old: public: static void __cdecl std::_String_base::_Xran(void)

new: public: void __thiscall std::basic_string::_Xran(void) (this might be wrong, but you get the idea)

There are three possible fixes:

1) Compile all libraries with VS 2010

2) Use the older version of VS to compile your code

3) Rewrite the existing _XRan and _XLen implemenations and override in linker (see JN123's explanation in http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/5ac28a31-3339-4db1-90f4-68edad360309).


Faced same problem migrating for 2008 to 2012. It seems MS still playing with these functions' signatures. My decision is just to give linker what it wants. I've placed next code into my project's cpp and linker was shut up:

namespace std
{
    class _String_base
    { 
    public:
        static void _cdecl _Xlen(void) ; 
        static void _cdecl _Xran(void) ; 
    };
};

void _cdecl std::_String_base::_Xlen(void) 
{   // report a length_error
_Xlength_error("string too long");
}
void _cdecl std::_String_base::_Xran(void) 
{   // report an out_of_range error
_Xout_of_range("invalid string position");
}


Goto your project settings:

Configuration properties General - Platform tool set

  1. visual studio 2010 - vc100.
  2. visual studio 2008 - vc90.
  3. visual studio 2005 - vc80.


Goto your project settings:

Configuration properties General - Platform tool set

visual studio 2010 - vc100. visual studio 2008 - vc90. visual studio 2005 - vc80.

This require all these visual studio versions installed on your system. Otherwise you will get an error like this: "Specified platform toolset (v90) requires Visual Studio 2008. Please make sure that Visual Studio 2008 is installed on the machine."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜