1

I'm compiling a trivial C++ file Temp.cpp:

#include <string>
int main() { std::wstring s; }

With the command line:

cl.exe /MD /Iinc\api\crt\stl60 /Iinc\crt /Iinc\api C:\Temp.cpp
       /LibPath:lib\wxp\i386 /LibPath:lib\crt\i386
       /link /LibPath:lib\wxp\i386 /LibPath:lib\crt\i386

in the WDK 7.1 Windows XP Free Build Environment.

I get link errors like (LNK2019):

unresolved external symbol "__declspec(dllimport) public: __thiscall
    std::basic_string<wchar_t,struct std::char_traits<wchar_t>,
    class std::allocator<wchar_t> >::~basic_string<wchar_t,
    struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >(void)"
    (__imp_??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator
     @_W@2@@std@@QAE@XZ) referenced in function _main

If I use string instead of wstring, it works.

What's the cause of the problem? How can I use wchar_t-based types in my source file?

3
  • Does WDK refer to the Windows SDK?
    – jalf
    May 13, 2011 at 7:11
  • @jalf: No, it's the Windows Driver Kit.
    – user541686
    May 13, 2011 at 7:11
  • @Andreas: Didn't do anything, although I'm suspecting it might be something similar... :(
    – user541686
    May 13, 2011 at 7:13

2 Answers 2

6

The likely fix would be to set /Zc:wchar_t- to turn off wchar_t as an intrinsic type. STL6 doesn't have great support for /Zc:wchar_t which is the default since at least VC7.1, perhaps earlier.

Meta: Please don't use the STL60 version of STL. This version from 1998 lacks a large number of bug fixes, performance improvements and standards-conformance work that you can find in a modern STL. If you are using the VC compiler toolchain the free VC++ express includes STL.

Martyn

2
  • You're brilliant!!! That solved it, thanks a LOT (saved me so much more pain)! :)
    – user541686
    May 13, 2011 at 7:18
  • Good, now upgrade your compiler to something from this millennium. ;)
    – jalf
    May 13, 2011 at 7:29
0

VC6 doesn't support the wchar_t type , it had a typedef for unsigned short. The linker would only be able to find std::basic_string<unsigned short> in the "stl60" lib.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.