Tim
Tim

Reputation: 20360

How do I resolve this linker error (unicode, boost, TCHAR/tstring (visual studio 2008))

We just "ported" our app to Unicode and I am having difficulty with some linking.

I wonder if I may be missing some other flag because I am not sure what the name mangling below means:

This is the link error I get

Error 31 error LNK2019: unresolved external symbol "public: class boost::shared_ptr __thiscall ResourceManager::GetImage(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &,bool)" (?GetImage@ResourceManager@@QAE?AV?$shared_ptr@VPngImage@@@boost@@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@_N@Z) referenced in function "public: long __thiscall ATL::CAxWindowT::QueryHost(struct _GUID const &,void * *)" (?QueryHost@?$CAxWindowT@VCWindow@ATL@@@ATL@@QAEJABU_GUID@@PAPAX@Z) wndGroupSearch.obj

The method is in the code. It is declared like so:

boost::shared_ptr<PngImage> GetImage(const tstring& name, bool bLocalizedOnly = false );

When I run dumpbin on the lib that does not link I get the following:

public: class boost::shared_ptr<class PngImage> __thiscall ResourceManager::GetImage(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,bool))
    ?GetImage@ResourceManager@@QAE?AV?$shared_ptr@VPngImage@@@boost@@ABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@_N@Z

When I dump the Debug version (That does link correctly) I get the following in the dumpbin for the lib

public: class boost::shared_ptr<class PngImage> __thiscall ResourceManager::GetImage(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &,bool)" (?GetImage@ResourceManager@@QAE?AV?$shared_ptr@VPngImage@@@boost@@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@_N@Z)
?GetImage@ResourceManager@@QAE?AV?$shared_ptr@VPngImage@@@boost@@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@_N@Z (public: class boost::shared_ptr<class PngImage> __thiscall ResourceManager::GetImage(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &,bool))

Is there some boost issue or perhaps a compile or link flag I am missing to fix this?

It works in our debug unicode build, but not in release build. I have not yet found why the mangled names look different:

?$basic_string@GU?$char_traits vs ?$basic_string@_WU?$char_traits

and the friendlier names are:

ResourceManager::GetImage(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &,bool)

vs

ResourceManager::GetImage(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,bool))

wchar_t and GU vs unsigned short _WU

Any suggestions?

Upvotes: 1

Views: 1277

Answers (1)

Bo Persson
Bo Persson

Reputation: 92361

It seems like there are some references to basic_string<wchar_t> and some references to basic_string<unsigned short>. This could be because the option

/Zc:wchar_t Treat wchar_t as a native types

is not set consistently for all files.

Upvotes: 4

Related Questions