CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2002
    Posts
    2

    Link error using STL in VC7

    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

  2. #2
    Join Date
    Jul 2002
    Posts
    2
    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

  3. #3
    Join Date
    Aug 2006
    Posts
    1

    Re: Link error using STL in VC7

    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.

  4. #4
    Join Date
    Oct 2006
    Posts
    2

    Re: Link error using STL in VC7

    I was also facing the same problem. I made the project link with MFC library and it worked fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured