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 F开发者_运维问答ree 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?
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
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.
精彩评论