Link Error using STL in VC7 
Author Message
 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 " (?

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



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

Quote:
}

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



Wed, 29 Dec 2004 06:07:46 GMT  
 Link Error using STL in VC7
    I just copied and pasted your code into my VS 6.0 (sp 5) and also into
VS.NET and it ran fine except for the warning for main to return something
because it's declared as int main().

    What platform are you running on?.


Quote:
> 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 " (?

> 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



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

> 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



Wed, 29 Dec 2004 21:48:51 GMT  
 Link Error using STL in VC7
I'd shown the function for the sake of brevity. I've
actually created a Win32 project(exe) in Visual Studio 7
and it's as below:
#include <string>
using namespace std;

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                        
                        // current instance
TCHAR szTitle[MAX_LOADSTRING];                          
        // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];                    //
the main window class name

// Forward declarations of functions included in this code
module:
ATOM                            MyRegisterClass(HINSTANCE
hInstance);
BOOL                            InitInstance(HINSTANCE,
int);
LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM,
LPARAM);
LRESULT CALLBACK        About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
        // TODO: Place code here.
        MSG msg;
        HACCEL hAccelTable;

        // Initialize global strings
        LoadString(hInstance, IDS_APP_TITLE, szTitle,
MAX_LOADSTRING);
        LoadString(hInstance, IDC_TESTHARNESS,
szWindowClass, MAX_LOADSTRING);
        MyRegisterClass(hInstance);

        // Perform application initialization:
        if (!InitInstance (hInstance, nCmdShow))
        {
                return FALSE;
        }

        hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)
IDC_TESTHARNESS);
        string sTmp( "test" );
        // Main message loop:
        while (GetMessage(&msg, NULL, 0, 0))
        {
                if (!TranslateAccelerator(msg.hwnd,
hAccelTable, &msg))
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }
        }

        return (int) msg.wParam;

Quote:
}

I'm running Windows 2000.  
I just wonder if it's just an environment thing on my
machine with not having installed stuff correctly.  As
you've demonstrated, I'm doing something real simple.
Any help will be appreciated.

Thanks
Srinivas

Quote:
>-----Original Message-----
>    I just copied and pasted your code into my VS 6.0 (sp
5) and also into
>VS.NET and it ran fine except for the warning for main to
return something
>because it's declared as int main().

>    What platform are you running on?.


message

>> 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 " (?

>> 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




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

>> 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

>.



Sat, 01 Jan 2005 00:10:29 GMT  
 Link Error using STL in VC7
Marilyn,
thanks for your help.
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.

Thanks again
Srinivas

Quote:
>-----Original Message-----
>I'd shown the function for the sake of brevity. I've
>actually created a Win32 project(exe) in Visual Studio 7
>and it's as below:
>#include <string>
>using namespace std;

>#define MAX_LOADSTRING 100

>// Global Variables:
>HINSTANCE hInst;                                    
>                    // current instance
>TCHAR szTitle[MAX_LOADSTRING];                              
>    // The title bar text
>TCHAR szWindowClass[MAX_LOADSTRING];                        //
>the main window class name

>// Forward declarations of functions included in this
code
>module:
>ATOM                                MyRegisterClass(HINSTANCE
>hInstance);
>BOOL                                InitInstance(HINSTANCE,
>int);
>LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM,
>LPARAM);
>LRESULT CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

>int APIENTRY _tWinMain(HINSTANCE hInstance,
>                     HINSTANCE hPrevInstance,
>                     LPTSTR    lpCmdLine,
>                     int       nCmdShow)
>{
>    // TODO: Place code here.
>    MSG msg;
>    HACCEL hAccelTable;

>    // Initialize global strings
>    LoadString(hInstance, IDS_APP_TITLE, szTitle,
>MAX_LOADSTRING);
>    LoadString(hInstance, IDC_TESTHARNESS,
>szWindowClass, MAX_LOADSTRING);
>    MyRegisterClass(hInstance);

>    // Perform application initialization:
>    if (!InitInstance (hInstance, nCmdShow))
>    {
>            return FALSE;
>    }

>    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)
>IDC_TESTHARNESS);
>    string sTmp( "test" );
>    // Main message loop:
>    while (GetMessage(&msg, NULL, 0, 0))
>    {
>            if (!TranslateAccelerator(msg.hwnd,
>hAccelTable, &msg))
>            {
>                    TranslateMessage(&msg);
>                    DispatchMessage(&msg);
>            }
>    }

>    return (int) msg.wParam;
>}

>I'm running Windows 2000.  
>I just wonder if it's just an environment thing on my
>machine with not having installed stuff correctly.  As
>you've demonstrated, I'm doing something real simple.
>Any help will be appreciated.

>Thanks
>Srinivas

>>-----Original Message-----
>>    I just copied and pasted your code into my VS 6.0
(sp
>5) and also into
>>VS.NET and it ran fine except for the warning for main
to
>return something
>>because it's declared as int main().

>>    What platform are you running on?.


>message

>>> 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 " (?

>>> 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




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

>>> It compiles fine but gives the Link error above.
>>> This is the first time I'm using STL in VC7 (Visual
>>> Stu{ w j T g   g  ? dio.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 generat



Sat, 01 Jan 2005 01:20:39 GMT  
 Link Error using STL in VC7
Hi folks,

I'm suffering from the identical problem...with a twist.

Here's my setup:
 1 LIB that I do NOT have source code for.
   The LIB uses STL.
   The LIB has been compiled using Visual Studio 6.

 1 EXE that I have source code for.
   The EXE uses STL.
   The EXE statically links the LIB.
   The EXE compiles & links perfectly under Visual Studio 6.

When I try to compile the EXE under Visual Studio 7,
I get the above errors mentioned - _Xlen() and _Xran() are
required by the LIB but are defined differently by the
Visual Studio 7 CRT DLLs.

I've tried changing the search order (as described in the below post)
for the CRT DLLs, but then my EXE complains that it can't find
some VS 7 CRT functions. (!)

I can't simply recompile/fix the LIB under VS 7 because I don't
have the source code.

Somehow it seems, I have to use both the VS 6 CRT DLLs (for the LIB)
and the VS 7 CRT DLLs (for the EXE).  But I think this might be
impossible...

Any thoughts?
Thanks,
Sameer

Btw, here's what I've tried:
 - Using different directory paths in hopes that the LIB
   and EXE can use 2 different versions of the CRT. (didn't work)
 - Try to manually define _Xlen()/_Xran() in the EXE (std namespace)
   so that the LIB can link.  This works, but then when
   I try to call a function in my LIB, it seems to crash
   one instruction after the function returns.
   Here's what i pasted in my EXE to make things compile:
        _STD_BEGIN
        // report a length_error
        __declspec(dllexport) void __cdecl _Xlen()
        {_THROW(length_error, "string too long"); }
        // report an out_of_range error
        __declspec(dllexport) void __cdecl _Xran()
        {_THROW(out_of_range, "invalid string position"); }
        _STD_END

Quote:

> Marilyn,
> thanks for your help.
> 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.

> Thanks again
> Srinivas

> >-----Original Message-----
> >I'd shown the function for the sake of brevity. I've
> >actually created a Win32 project(exe) in Visual Studio 7
> >and it's as below:
> >#include <string>
> >using namespace std;

> >#define MAX LOADSTRING 100

> >// Global Variables:
> >HINSTANCE hInst;                                      
> >                       // current instance
> >TCHAR szTitle[MAX LOADSTRING];                        
> >       // The title bar text
> >TCHAR szWindowClass[MAX LOADSTRING];                   //
> >the main window class name

> >// Forward declarations of functions included in this
>  code
> >module:
> >ATOM                           MyRegisterClass(HINSTANCE
> >hInstance);
> >BOOL                           InitInstance(HINSTANCE,
> >int);
> >LRESULT CALLBACK       WndProc(HWND, UINT, WPARAM,
> >LPARAM);
> >LRESULT CALLBACK       About(HWND, UINT, WPARAM, LPARAM);

> >int APIENTRY  tWinMain(HINSTANCE hInstance,
> >                     HINSTANCE hPrevInstance,
> >                     LPTSTR    lpCmdLine,
> >                     int       nCmdShow)
> >{
> >       // TODO: Place code here.
> >       MSG msg;
> >       HACCEL hAccelTable;

> >       // Initialize global strings
> >       LoadString(hInstance, IDS APP TITLE, szTitle,
> >MAX LOADSTRING);
> >       LoadString(hInstance, IDC TESTHARNESS,
> >szWindowClass, MAX LOADSTRING);
> >       MyRegisterClass(hInstance);

> >       // Perform application initialization:
> >       if (!InitInstance (hInstance, nCmdShow))
> >       {
> >               return FALSE;
> >       }

> >       hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)
> >IDC TESTHARNESS);
> >       string sTmp( "test" );
> >       // Main message loop:
> >       while (GetMessage(&msg, NULL, 0, 0))
> >       {
> >               if (!TranslateAccelerator(msg.hwnd,
> >hAccelTable, &msg))
> >               {
> >                       TranslateMessage(&msg);
> >                       DispatchMessage(&msg);
> >               }
> >       }

> >       return (int) msg.wParam;
> >}

> >I'm running Windows 2000.  
> >I just wonder if it's just an environment thing on my
> >machine with not having installed stuff correctly.  As
> >you've demonstrated, I'm doing something real simple.
> >Any help will be appreciated.

> >Thanks
> >Srinivas

> >>-----Original Message-----
> >>    I just copied and pasted your code into my VS 6.0
>  (sp
>  5) and also into
> >>VS.NET and it ran fine except for the warning for main
>  to
>  return something
> >>because it's declared as int main().

> >>    What platform are you running on?.


>  message

> >>> 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 " (?

> >>> 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




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

> >>> It compiles fine but gives the Link error above.
> >>> This is the first time I'm using STL in VC7 (Visual
> >>> Stu??w?j T? g   g??
>  ?dio.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 generat



Sun, 02 Jan 2005 07:24:10 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Link error when using STL

2. VC7.1: Internal compiler error in STL headers

3. STL queue linker error moving from VC6 to VC7

4. compiler error C2582 of STL streams from VC6 to VC7

5. Using VC7's STL in VC6?

6. Using VC7 STL in VC6?

7. stl map iterator corrupted in dll using vc7 .net

8. VC7 Link error compiling ADO code (no problem in VC6)

9. VC7 Link error compiling ADO code (no problem in VC6)

10. Link errors with VC7 on CFileDialog and CPropertyPage

11. template function specialization causing link error in VC7

12. same link errors in VC7 as VC6

 

 
Powered by phpBB® Forum Software