16

今天我从2008年更新到2010年的VS版本后遇到了链接问题,错误是这样的:

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)

我在网上搜索了这个问题,并在这个地址找到了一个类似的帖子:http: //social.msdn.microsoft.com/Forums/en/vcgeneral/thread/5ac28a31-3339-4db1-90f4-68edad360309

但是这些答案都不能解决我的问题。谁能给我一些关于如何解决这个问题的提示?

非常感谢您的帮助!

4

4 回答 4

15

问题很可能是您的 .exe 链接的库之一是使用以前版本的 Visual Studio 构建的。因为这个“其他”库是用以前版本的 VS 编译的,所以它在 VS2010 C 运行时中寻找函数 _XRan 和 _XLen 的以前版本。MS 已经改变了它们(再次),它们旧的函数签名在 VS2010 运行时中不存在。

旧:公共:静态无效 __cdecl std::_String_base::_Xran(void)

新:public:void __thiscall std::basic_string::_Xran(void) (这可能是错误的,但你明白了)

有三种可能的修复方法:

1)用VS 2010编译所有库

2)使用老版本的VS编译你的代码

3) 重写现有的 _XRan 和 _XLen 实现并在链接器中覆盖(请参阅http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/5ac28a31-3339-4db1-90f4-68edad360309中的 JN123 的解释)。

于 2010-06-21T20:06:22.530 回答
4

在 2008 年到 2012 年迁移时面临同样的问题。似乎 MS 仍在使用这些函数的签名。我的决定只是给链接器它想要的东西。我已将下一个代码放入项目的 cpp 中,并且链接器已关闭:

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");
}
于 2014-08-26T12:27:09.790 回答
3

转到您的项目设置:

配置属性常规 - 平台工具集

  1. 视觉工作室 2010 - vc100。
  2. 视觉工作室 2008 - vc90。
  3. 视觉工作室 2005 - vc80。
于 2012-01-03T21:32:15.197 回答
1

转到您的项目设置:

配置属性常规 - 平台工具集

视觉工作室 2010 - vc100。视觉工作室 2008 - vc90。视觉工作室 2005 - vc80。

这需要在您的系统上安装所有这些 Visual Studio 版本。否则你会得到类似这样的错误:“Specified platform toolset (v90) requires Visual Studio 2008. Please make sure the Visual Studio 2008 is installed on the machine.”

于 2012-01-08T14:40:01.897 回答