Linker Error When Using Qt and Boost

When I use Qt (v4.7.4) and Boost (tested 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 installed Qt before the code worked without problems.

This error message is:

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

... obj: error LNK2001: unresolved external character "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 @@ stand @@ ABV? $ codecvt @ GDH @ 5 @@ Z)

... obj: error LNK2001: unresolved external character "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 @@ standard @@ ABV? $ Codecvt @GDH @ 6 @@ Z)

... obj: error LNK2001: unresolved external character "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 external

EDIT:

Here I found that this issue raises the following question:

this is really a Qt problem. Using wchar_t as a native type, you must recompile Qt using the same compiler switch. There is even an error in the tracker: https://bugreports.qt.io/browse/QTBUG-9617

In general, you need to be very careful not to mix the wchar_t compiler in your projects, as they will become incompatible.

So, I recompiled the Qt /Zc:wchar_t setup, but it showed no effect. I still get the same error.

+7
source share
3 answers

I think you are on the right track, but it looks like your -Zc:wchar_t not "sticking". We had to do the same to make Qt happy with the Google Breakpad and the ICU library. We changed the /Zc:wchar_t setting to (QT_SOURCE)\mkspecs\win32-msvc2008\qmake.conf and compiled Qt from the source, and then everything works.

When you create a 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 already created Qt without this option, you might have to do make confclean first so that everything will really recover with the new settings.

It looks like - Zc: wchar_t will be used by default in Qt 5 .

+8
source

Using boost-1.49, Qt 4.4 and VS2005 had the same problem. Going to the project properties and then setting "Configuration Properties → C / C ++ → Language → Treat wchar_t as a built-in type" to "Yes" fixes the problem.

+2
source

Qt may have changed the typology of your program with respect to the configuration of the runtime: therefore, it will find the acceleration library that you use (file system), which are included in many configurations that can be accessed by the symbol connot.

For example, multi-threaded runtimes require mt somewhere in the name of the library (I hope I remember it well, but in any case see the documents where the details are fully documented). This naming is pretty transparent to the programmer, because of the pragmas that encourage programmers suitable to facilitate the use of the library in different compilers.

You should skip the non-wchar filesystem.lib. When I used Windows, I used boost Jam to interact with Visual C ++ (perhaps this refers to the last millennium!). I hope it is still useful.

0
source

All Articles