7
votes

When I am using Qt (v4.7.4) and Boost (tried v1.47 and v1.48) together in my c++ project, I get a linker error caused by a class that includes <boost\filesystem.hpp>. I just set up Qt and before the code was working without any problems.

This is error message:

...obj : error LNK2001: unresolved external symbol "private: static class std::codecvt const * & __cdecl boost::filesystem3::path::wchar_t_codecvt_facet(void)" (?wchar_t_codecvt_facet@path@filesystem3@boost@@CAAAPBV?$codecvt@GDH@std@@XZ)

...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::convert(char const *,char const *,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?convert@path_traits@filesystem3@boost@@YAXPBD0AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@ABV?$codecvt@GDH@5@@Z)

...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::dispatch(class boost::filesystem3::directory_entry const &,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?dispatch@path_traits@filesystem3@boost@@YAXABVdirectory_entry@23@AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@ABV?$codecvt@GDH@6@@Z)

...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::convert(unsigned short const *,unsigned short const *,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?convert@path_traits@filesystem3@boost@@YAXPBG0AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$codecvt@GDH@5@@Z)

...exe : fatal error LNK1120: 4 unresolved externals

EDIT:

Here I found someone having this problem coming to this conclusion:

this really is a Qt issue. Using wchar_t as a native type you have to recompile Qt using the same compiler switch. There even is a bug in the tracker: https://bugreports.qt.io/browse/QTBUG-9617

In general, you will have to be very careful and do not mix wchar_t compiler settings in your projects as they will become incompatible.

So I recompiled Qt setting /Zc:wchar_t, but it didn't show any effect. I still get the same error.

3
have you compiled boost? I'm not too familiar with what exactly needs building but some libraries do.pezcode
yes. I've compiled it for Visual Studio 2010 using b2.exe if I remember correctly.Pedro
might it be necessary to recompile the whole boost library? I don't remember the exact build configuration, but I definitely didn't change treat wchar_t as build-in type property when I was compiling boost.Pedro
Could you include at least line from your compiler output? Perhaps cl ...? It sounds to me like your /Zc:wchar_t didn't take for some reason. Your compiler output would show that.Dave Mateer
Sorry, I just meant when you compile the program that is causing the problem. The "Compile Output" window shows the commands used to compile the program. You should have something like cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -WX ... blah ... blah ... blahDave Mateer

3 Answers

8
votes

I think you are on the right track, but it sounds like your -Zc:wchar_t didn't "stick." We had to do the same thing to make Qt happy with Google Breakpad and the ICU library. We changed the /Zc:wchar_t setting in (QT_SOURCE)\mkspecs\win32-msvc2008\qmake.conf and compiled Qt from source, and after that everything works.

When you build your project that uses Qt and Boost, you should see this option in the compiler output. Something like:

cl -c -nologo -Zm200 -Zc:wchar_t ... (etc.)

If you've already build Qt without this option, you may have to do a make confclean first to ensure everything really gets rebuilt with the new settings.

It sounds like -Zc:wchar_t will be the default in Qt 5.

2
votes

Using boost-1.49, Qt 4.4 and VS2005 had the same problem. Going to project properties, then setting "Configuration Properties -> C/C++ -> Language -> Treat wchar_t as Built-in Type" to "Yes" fixed the problem.

0
votes

Qt probably changed the tipology of your program with regards the configuration of the runtime: consequently, the boost library you use (filesystem), that come in many configuration accessed by naming convention - connot be found.

For instance, multithread runtimes require mt somewhere in library name (I hope I remember well, but anyway see the docs where details are fully documented). This naming is fairly transparent to the programmer, due to pragmas that boost programmers appropriately used to ease the library usage under different compilers.

You should miss the non-wchar filesystem.lib. When I used Windows, I used boost Jam to interface with Visual C++ (may be that goes back to the past millenium!). I hope it's still usable.