2010-07-19 15 views
2

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

在我的項目中,我從鏈接器中得到了幾個'未解決的令牌'錯誤,用於stlport的東西。例如爲:

1>moc_ParentWidget.obj : error LNK2020: unresolved token (0A000819) "public: __thiscall stlp_std::allocator<unsigned short>::~allocator<unsigned short>(void)" ([email protected]@[email protected]@[email protected]) 
1>ParentWidget.obj : error LNK2028: unresolved token (0A0008EB) "public: __thiscall stlp_std::allocator<unsigned short>::~allocator<unsigned short>(void)" ([email protected]@[email protected]@[email protected]) 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 " ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]@[email protected]) 
1>Terra3DViewNet.obj : error LNK2028: unresolved token (0A00087D) "public: __thiscall stlp_std::allocator<unsigned short>::~allocator<unsigned short>(void)" ([email protected]@[email protected]@[email protected]) 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 " ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]@[email protected]) 
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)" ([email protected][email protected]@[email protected]@@[email protected][email protected]@[email protected]) 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 &)" ([email protected][email protected]@[email protected]@@[email protected][email protected]@[email protected][email protected]@[email protected]@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)" ([email protected][email protected]@[email protected]@@[email protected][email protected]@[email protected]) 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 &)" ([email protected][email protected]@[email protected]@@[email protected][email protected]@[email protected][email protected]@[email protected]@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)" ([email protected][email protected]@[email protected]@@[email protected][email protected]@[email protected]) 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 &)" ([email protected]?$al[email protected]@[email protected]@@[email protected][email protected]@[email protected][email protected]@[email protected]@Z) 
1>moc_ParentWidget.obj : error LNK2020: unresolved token (0A000DE1) "public: void __thiscall stlp_std::allocator<unsigned short>::deallocate(unsigned short *,unsigned int)" ([email protected][email protected]@[email protected]@[email protected]) 
1>ParentWidget.obj : error LNK2028: unresolved token (0A000F27) "public: void __thiscall stlp_std::allocator<unsigned short>::deallocate(unsigned short *,unsigned int)" ([email protected][email protected]@[email protected]@[email protected]) 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)" ([email protected][email protected]@[email protected]@@[email protected][email protected]@[email protected]) 
... 

我檢查如果功能被包括在STLport的庫/ DLL和當前具有稍微不同未修飾名稱的功能。所以我想調用約定有什麼問題!?有任何想法嗎?

+1

當提供不完整的錯誤消息並且沒有提供代碼時,它會阻止幫助。 – Cogwheel 2010-07-19 16:21:23

+0

我更新了鏈接器的錯誤消息。我希望這有幫助! – 2010-07-19 16:23:18

+0

你使用VC++嗎?如果是這樣,你有沒有試過內置的STL?另外,Qt是否也在混合(我正在從「moc_」中猜測)?把Qt和第三方STL放在.Net之上似乎有些過分...... – Cogwheel 2010-07-19 16:45:57

回答

3

我解決了這個問題。問題在於stlport是使用wchar_t作爲內置類型處理的,.NET部分是在沒有此選項的情況下編譯的。

由於這個wchar_t在.NET中被視爲unsigned short並導致無法解析的外部符號。

0

C++編譯器使用name mangling,例如。使用MSVC++編譯時,「void h(int)」變爲「?h @@ YAXH @ Z」6/7

但是,編譯器之間甚至編譯器版本之間的名稱轉換不同。您的DLL可能是使用不同的編譯器或使用不同名稱的較舊版本的編譯器編譯的。嘗試使用您正在使用的編譯器重新編譯庫。

+0

我爲項目的所有部分使用Visual Studio 2008。所以我絕對使用相同的編譯器和編譯器版本。 – 2010-07-20 07:33:08

+0

但您是否也使用Visual Studio 2008編譯stlport? – Tomaka17 2010-07-20 07:44:24

+0

當然可以。我使用了StlPort,Qt和我當前項目的相同編譯器。所有使用相同的編譯器設置(除了CLR的東西)。 – 2010-07-20 08:37:47