2

Is it possible to use stlport within a Managed C++ DLL?

In my project i get several 'unresolved token'-errors from the linker for stlport stuff. 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)
...

I checked if the functions are included in the stlport library/DLL and the functions a present with a slightly different undecorated name. So i suppose there's something wrong with calling convention!? Any ideas?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Andreas Roth
  • 699
  • 2
  • 9
  • 30
  • 1
    When incomplete error messages and no code are provided it hinders efforts to help. – Cogwheel Jul 19 '10 at 16:21
  • I updated the error message from the linker. I hope this helps! – Andreas Roth Jul 19 '10 at 16:23
  • Are you using VC++? If so, have you tried the built-in STL? Also, is that Qt you're mixing in as well (I'm guessing from the "moc_" stuff)? It seems a bit excessive to pile Qt and a third-party STL on top of .Net... – Cogwheel Jul 19 '10 at 16:45
  • You're right. I'm using Qt. And i've successfully built Qt with Stlport without any problems, since it's unmanaged code only. I only have problems in a .NET module, which tries to use some unmanaged DLLs. The built-in STL is not an option, since the performance is quite bad in the debug version and we need some options to reduce the debug overhead on STL. That's why we chose stlport. – Andreas Roth Jul 20 '10 at 07:35

2 Answers2

3

I solved the problem. The issue was that the stlport was compiled with wchar_t treated as built-in type and the .NET part was compiled without this option.

Because of this wchar_t was treated as unsigned short in .NET and caused the unresolved external symbols.

Andreas Roth
  • 699
  • 2
  • 9
  • 30
0

C++ compilators use name mangling, eg. "void h(int)" becomes "?h@@YAXH@Z" when compiling with MSVC++ 6/7

However the name conversions differ between compilers, and even between compiler versions. Your DLL was probably compiled with a different compiler or an older version of the compiler which used different names. Try to recompile the library with the compiler you're using.

Tomaka17
  • 4,832
  • 5
  • 29
  • 38
  • I'm using Visual Studio 2008 for all parts of the project. So i definitely use the same compiler and compiler version for everything. – Andreas Roth Jul 20 '10 at 07:33
  • But did you compile stlport with Visual Studio 2008 too? – Tomaka17 Jul 20 '10 at 07:44
  • Yes of course. I used the same compiler for StlPort, Qt and my current project. All with the same compiler settings (except for the CLR stuff). – Andreas Roth Jul 20 '10 at 08:37