是否在C++ WDK STL中支持wchar_t?我得到未解决的外部符号:(

Meh*_*dad 1 c++ winapi stl wdk windows-7

我正在编译一个简单的C++文件Temp.cpp:

#include <string>
int main() { std::wstring s; }
Run Code Online (Sandbox Code Playgroud)

使用命令行:

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
Run Code Online (Sandbox Code Playgroud)

在WDK 7.1 Windows XP免费构建环境中.

我收到链接错误,如(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
Run Code Online (Sandbox Code Playgroud)

如果我使用string而不是wstring,它的工作原理.

问题的原因是什么?如何wchar_t在源文件中使用基于类型的类型?

Mar*_*ell 6

可能的解决方法是将/ Zc:wchar_t-设置为关闭wchar_t作为内部类型.STL6对/ Zc:wchar_t没有很好的支持,这是至少VC7.1的默认值,可能更早.

Meta:请不要使用STL的STL60版本.1998年的这个版本缺少大量的错误修复,性能改进和标准一致性工作,您可以在现代STL中找到它们.如果您使用的是VC编译器工具链,则免费的VC++ express包含STL.

马丁