Search code examples
visual-studio-2010visual-studio-2008visual-c++wxwidgets

wxWidgets (static lib) will not link under VC++ 2010


I cannot get a wxWidgets program that uses the wxWidgets static libraries to compile and link properly under VC++ 2010. Under VC++ 2008, it's fine. (WxWidgets still ships with vc++ 2008 project files.)

I compiled and ran the "minimal" sample program that comes with wxWidgets. It is a GUI hello world. No problem. I used VC++ 2010 to convert the .vsproj to .vsxproj and attempt to compile and link under VC++ 2010. Problem.

Be assured that I changed absolutely nothing other than to run the VC++ 2010 conversion to create minimal.vsxproj.

I got many linker warnings and errors, all having to do with STL wchar_t strings in the wxWidgets libs. Here is what I think is happening. I believe there must be #ifdefs in the wxWidgets code that select __declspec(import) or not, based on preprocessor symbols. When VC++ 2010 converted the project, it must have changed the symbols to something that fools wxWidgets. If so, the bug could be in either place, either wxWidgets is making invalid assumptions about pre-processor definitions, or the VC++ 2010 conversion messed them up. The command lines for compiling the lone .cpp file in the project differ more than I would expect them to.

2008 command line

/Od /I ".....\lib\vc_lib\mswud" /I ".....\include" /I "." /I ".....\samples" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE=1" /D "_CRT_NON_CONFORMING_SWPRINTFS=1" /D "_SCL_SECURE_NO_WARNINGS=1" /D "WXMSW" /D "_UNICODE" /D "_WINDOWS" /D "NOPCH" /D "UNICODE" /FD /EHsc /RTC1 /MDd /Fo"vc_mswud\minimal\" /Fd"vc_mswud\minimal.pdb" /W4 /nologo /c /Zi /TP /errorReport:prompt /MP

2010 command line

/I".....\lib\vc_lib\mswud" /I".....\include" /I"." /I".....\samples" /Zi /nologo /W4 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE=1" /D "_CRT_NON_CONFORMING_SWPRINTFS=1" /D "_SCL_SECURE_NO_WARNINGS=1" /D "WXMSW" /D "_UNICODE" /D "_WINDOWS" /D "NOPCH" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /GR /Fp"vc_mswud\minimal\minimal.pch" /Fa"vc_mswud\minimal\" /Fo"vc_mswud\minimal\" /Fd"vc_mswud\minimal.pdb" /Gd /analyze- /errorReport:queue

Example 2010 warning and error

1>wxbase29ud.lib(ipcbase.obj) : warning LNK4049: locally defined symbol ??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ (public: __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::~basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >(void)) imported

1>wxbase29ud.lib(mimecmn.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > & __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::assign(class std::_String_const_iterator<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >,class std::_String_const_iterator<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" (__imp_?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@V?$_String_const_iterator@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@2@0@Z)

Solution

  • You absolutely must build wxWidgets and the application using it with the same version of the compiler, different MSVC versions use different, incompatible versions of the CRT and so there is no chance at all that you can use VC10 to build an application and link it with wxWidgets built with VC9.

    As for building wx itself with VC10, there are indeed sometimes some problems when importing VC9 projects, the custom build rules can somehow be mangled. If this happens to you (although AFAIK nobody reported it for wx 2.9.4 project files yet), just copy the custom build rules for setup.h manually or simply execute them yourself manually.

    FWIW we hope to have "native" VC10 and VC11 projects in 3.0 release (coming soon).