Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linker error when using Qt and Boost

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.

like image 912
Pedro Avatar asked Nov 19 '11 19:11

Pedro


People also ask

How do you fix a linker error?

You can fix the errors by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass . obj files or . lib files that contain the definitions to the linker.

What causes linker errors?

Linker errors occur when the linker is trying to put all the pieces of a program together to create an executable, and one or more pieces are missing. Typically, this can happen when an object file or libraries can't be found by the linker.


1 Answers

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.

like image 115
Dave Mateer Avatar answered Oct 12 '22 11:10

Dave Mateer