C++ 是否支持 wchar_t WDK STL?我得到未解析的外部符号:(
我正在编译一个简单的 C++ 文件 Temp.cpp
:
#include <string>
int main() { std::wstring s; }
使用命令行:
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
在 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
如果我使用 string
而不是 wstring
,它就可以工作。
问题的原因是什么?如何在源文件中使用基于 wchar_t
的类型?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能的修复方法是设置 /Zc:wchar_t- 以关闭 wchar_t 作为内在类型。 STL6 对 /Zc:wchar_t 没有很好的支持,这是至少从 VC7.1 开始(也许更早)的默认设置。
Meta:请不要使用STL60版本的STL。这个 1998 年的版本缺乏现代 STL 中可以找到的大量错误修复、性能改进和标准一致性工作。如果您使用 VC 编译器工具链,则免费的 VC++ Express 包含 STL。
马丁
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 不支持
wchar_t
type ,它有一个typedef
表示unsigned Short
。链接器只能在“stl60”库中找到std::basic_string
。VC6 doesn't support the
wchar_t
type , it had atypedef
forunsigned short
. The linker would only be able to findstd::basic_string<unsigned short>
in the "stl60" lib.