是否可以在托管C ++ DLL中使用stlport?
在我的项目中,我从链接器中获取了几个“未解析的令牌”错误。 e.g:
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中,以及函数是否存在与未修饰的名称略有不同。所以我认为召集会议有问题!?有什么想法吗?
答案 0 :(得分:3)
我解决了这个问题。问题是stlport是使用wchar_t编译为内置类型编译的,而.NET部分是在没有此选项的情况下编译的。
由于这个问题,wchar_t在.NET中被视为unsigned short并导致未解析的外部符号。
答案 1 :(得分:0)
C ++编译器使用name mangling,例如。使用MSVC ++ 6/7编译时,“void h(int)”变为“?h @@ YAXH @ Z”
然而,编译器之间的名称转换不同,甚至编译器版本之间也不同。您的DLL可能是使用不同的编译器或使用不同名称的旧版本编译器编译的。尝试使用您正在使用的编译器重新编译库。