【问题标题】:use stlport in managed c++在托管 C++ 中使用 stlport
【发布时间】:2011-03-18 00:02:40
【问题描述】:

是否可以在托管 C++ DLL 中使用 stlport?

在我的项目中,我从 stlport 内容的链接器中收到了几个“未解析的令牌”错误。例如:

1>moc_ParentWidget.obj : error LNK2020: unresolved token (0A000819) "public: __thiscall stlp_std::allocator<unsigned short>::~allocator<unsigned short>(void)" (??1?$allocator@G@stlp_std@@$$FQAE@XZ)
1>ParentWidget.obj : error LNK2028: unresolved token (0A0008EB) "public: __thiscall stlp_std::allocator<unsigned short>::~allocator<unsigned short>(void)" (??1?$allocator@G@stlp_std@@$$FQAE@XZ) referenced in function "public: class stlp_std::allocator<unsigned short> __thiscall stlp_std::vector<unsigned short,class stlp_std::allocator<unsigned short> >::get_allocator(void)const " (?get_allocator@?$vector@GV?$allocator@G@stlp_std@@@stlp_std@@$$FQBE?AV?$allocator@G@2@XZ)
1>Terra3DViewNet.obj : error LNK2028: unresolved token (0A00087D) "public: __thiscall stlp_std::allocator<unsigned short>::~allocator<unsigned short>(void)" (??1?$allocator@G@stlp_std@@$$FQAE@XZ) referenced in function "public: class stlp_std::allocator<unsigned short> __thiscall stlp_std::vector<unsigned short,class stlp_std::allocator<unsigned short> >::get_allocator(void)const " (?get_allocator@?$vector@GV?$allocator@G@stlp_std@@@stlp_std@@$$FQBE?AV?$allocator@G@2@XZ)
1>moc_ParentWidget.obj : error LNK2028: unresolved token (0A000B9F) "public: __thiscall stlp_std::priv::_STLP_alloc_proxy<unsigned short *,unsigned short,class stlp_std::allocator<unsigned short> >::~_STLP_alloc_proxy<unsigned short *,unsigned short,class stlp_std::allocator<unsigned short> >(void)" (??1?$_STLP_alloc_proxy@PAGGV?$allocator@G@stlp_std@@@priv@stlp_std@@$$FQAE@XZ) referenced in function "public: __thiscall stlp_std::priv::_Vector_base<unsigned short,class stlp_std::allocator<unsigned short> >::_Vector_base<unsigned short,class stlp_std::allocator<unsigned short> >(unsigned int,class stlp_std::allocator<unsigned short> const &)" (??0?$_Vector_base@GV?$allocator@G@stlp_std@@@priv@stlp_std@@$$FQAE@IABV?$allocator@G@2@@Z)
1>ParentWidget.obj : error LNK2028: unresolved token (0A000CC2) "public: __thiscall stlp_std::priv::_STLP_alloc_proxy<unsigned short *,unsigned short,class stlp_std::allocator<unsigned short> >::~_STLP_alloc_proxy<unsigned short *,unsigned short,class stlp_std::allocator<unsigned short> >(void)" (??1?$_STLP_alloc_proxy@PAGGV?$allocator@G@stlp_std@@@priv@stlp_std@@$$FQAE@XZ) referenced in function "public: __thiscall stlp_std::priv::_Vector_base<unsigned short,class stlp_std::allocator<unsigned short> >::_Vector_base<unsigned short,class stlp_std::allocator<unsigned short> >(unsigned int,class stlp_std::allocator<unsigned short> const &)" (??0?$_Vector_base@GV?$allocator@G@stlp_std@@@priv@stlp_std@@$$FQAE@IABV?$allocator@G@2@@Z)
1>Terra3DViewNet.obj : error LNK2028: unresolved token (0A000C5B) "public: __thiscall stlp_std::priv::_STLP_alloc_proxy<unsigned short *,unsigned short,class stlp_std::allocator<unsigned short> >::~_STLP_alloc_proxy<unsigned short *,unsigned short,class stlp_std::allocator<unsigned short> >(void)" (??1?$_STLP_alloc_proxy@PAGGV?$allocator@G@stlp_std@@@priv@stlp_std@@$$FQAE@XZ) referenced in function "public: __thiscall stlp_std::priv::_Vector_base<unsigned short,class stlp_std::allocator<unsigned short> >::_Vector_base<unsigned short,class stlp_std::allocator<unsigned short> >(unsigned int,class stlp_std::allocator<unsigned short> const &)" (??0?$_Vector_base@GV?$allocator@G@stlp_std@@@priv@stlp_std@@$$FQAE@IABV?$allocator@G@2@@Z)
1>moc_ParentWidget.obj : error LNK2020: unresolved token (0A000DE1) "public: void __thiscall stlp_std::allocator<unsigned short>::deallocate(unsigned short *,unsigned int)" (?deallocate@?$allocator@G@stlp_std@@$$FQAEXPAGI@Z)
1>ParentWidget.obj : error LNK2028: unresolved token (0A000F27) "public: void __thiscall stlp_std::allocator<unsigned short>::deallocate(unsigned short *,unsigned int)" (?deallocate@?$allocator@G@stlp_std@@$$FQAEXPAGI@Z) referenced in function "public: __thiscall stlp_std::priv::_Vector_base<unsigned short,class stlp_std::allocator<unsigned short> >::~_Vector_base<unsigned short,class stlp_std::allocator<unsigned short> >(void)" (??1?$_Vector_base@GV?$allocator@G@stlp_std@@@priv@stlp_std@@$$FQAE@XZ)
...

我检查了这些函数是否包含在 stlport 库/DLL 中,并且这些函数存在一个稍微不同的未修饰名称。所以我想调用约定有问题!?有什么想法吗?

【问题讨论】:

  • 如果错误消息不完整且未提供代码,则会阻碍帮助。
  • 我更新了来自链接器的错误消息。我希望这会有所帮助!
  • 你在用VC++吗?如果是这样,您是否尝试过内置的 STL?另外,您是否也在混入 Qt(我猜是“moc_”的东西)?在.Net之上堆放Qt和第三方STL似乎有点过分……
  • 你是对的。我正在使用 Qt。而且我已经成功地使用 Stlport 构建了 Qt,没有任何问题,因为它只是非托管代码。我只在 .NET 模块中遇到问题,它试图使用一些非托管 DLL。内置的 STL 不是一个选项,因为在调试版本中性能很差,我们需要一些选项来减少 STL 的调试开销。这就是我们选择 stlport 的原因。

标签: .net c++-cli stlport


【解决方案1】:

我解决了这个问题。问题是 stlport 编译时将 wchar_t 视为内置类型,而 .NET 部分编译时没有此选项。

由于这个 wchar_t 在 .NET 中被视为 unsigned short 并导致无法解析的外部符号。

【讨论】:

    【解决方案2】:

    C++ 编译器使用name mangling,例如。使用 MSVC++ 6/7 编译时,"void h(int)" 变为 "?h@@YAXH@Z"

    但是,编译器之间的名称转换不同,甚至编译器版本之间也不同。您的 DLL 可能是使用不同的编译器或使用不同名称的旧版本的编译器编译的。尝试使用您正在使用的编译器重新编译库。

    【讨论】:

    • 我在项目的所有部分都使用 Visual Studio 2008。所以我肯定对所有东西都使用相同的编译器和编译器版本。
    • 但是您是否也使用 Visual Studio 2008 编译了 stlport?
    • 当然可以。我对 StlPort、Qt 和我当前的项目使用了相同的编译器。所有都具有相同的编译器设置(CLR 的东西除外)。
    猜你喜欢
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多