Click to See Complete Forum and Search --> : Link error using STL in VC7


Srin50
July 15th, 2002, 11:25 AM
I'm simply trying to declare and initialize a std::string
variable and I get the following Link error:
error LNK2019: unresolved external symbol "public: void
__thiscall std::_String_base::_Xran(void)const " (?
_Xran@_String_base@std@@QBEXXZ) 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)

All I'm trying is the following:
#include <string>
using namespace std;
int main()
{
string s1("test");
return 0;
}

It compiles fine but gives the Link error above.
This is the first time I'm using STL in VC7 (Visual
Studio.NET).
It appears that the class basic_string< > is derived from
a class _String_base in the header <xstring>. The class
_String_base declares 2 methods: _Xlen() and _Xran() to
hold lenght and range error reporters. It is these two
methods which are generating the link errors.
I think the class _String_base is declared as
a 'dllimport' class (macro _CRTIMP2), butif that's the
case, I'm not sure which DLL it's defined in.

Any help on this is appreciated.

Thanks
Srinivas

Srin50
July 15th, 2002, 12:30 PM
I've figured it out to be an environment issue after all.
The include directory setting in Visual Studio was ordered
in a manner to link with VC6 first and VC7 later. I
switched the order around and things worked fine.

FYI
Srin

alqasrawi
August 28th, 2006, 08:36 AM
Hi,
i am facing the same trouble you got!
but i do not get to what you really did!
i do not understand your resolution on this!
please (greatly appreciated) would you explain more how you resolved this linking problem?
what are the includes you switched?
please note that currently i am using VS2005PRO (VC8).

thanks a lot!
Anas.

tvranjith
October 17th, 2006, 04:44 AM
I was also facing the same problem. I made the project link with MFC library and it worked fine.