Link error with String::fromWCharArray (Unresolved symbol)
-
I recently upgraded my project to Qt 5.0.0, and after fixing up some compile errors, i finally got it to compile successfully, only to get this link error:
bq. unresolved external symbol "__declspec(dllimport) public: static class QString __cdecl QString::fromWCharArray(unsigned short const *,int)" (_imp?fromWCharArray@QString@@SA?AV1@PBGH@Z)
After googling, i found some answers. But i checked and i have set "Treat wchar_t as built in type" to "no". And i have added Qt5Core.lib/Qt5Cored.lib to the linker. So i don't know what else to do.
-
"Here":http://pastebin.com/hW4zNHdH is the build output in diagnostic mode, if anyone is interested. I don't see much regarding linking, and the only reference to fromWCharArray are the final errors.
-
The problem is that for some inexplicable reason, the Qt developers flipped the Visual Studio C++ flag "Treat wchar_t as a built-in type" from "No" as it was in all previous versions of Qt (!!!) to "Yes" in Qt5.
This includes the pre-built Qt5 installers as well as the qmake.conf files for win32_msvcxxxx if you build from source.
What this means is that you must rebuild everything that you link to a Qt5 app that uses wchar_t (like STL std::wstring does), so that all those dependencies also define wchar_t as a built-in type.
Alternatively, you have to change the qmake.conf file for your MSVC compiler and rebuild all of Qt5 from source. Anywhere that QString is used will probably be touched by this, so that means you probably can't just rebuild QtCore where QString lives. (You would probably get link errors from all the other places in Qt that use QString, because the linker would be looking for QString::fromStdWString() and QString::toStdWString() with different arguments).
Who had the stupid idea that "Eh, it won't affect anyone if we change this flag, and we don't need to tell them or document it anywhere in the change notes"?
-
The problem is that for some inexplicable reason, the Qt developers flipped the Visual Studio C++ flag "Treat wchar_t as a built-in type" from "No" as it was in all previous versions of Qt (!!!) to "Yes" in Qt5.
This includes the pre-built Qt5 installers as well as the qmake.conf files for win32_msvcxxxx if you build from source.
What this means is that you must rebuild everything that you link to a Qt5 app that uses wchar_t (like STL std::wstring does), so that all those dependencies also define wchar_t as a built-in type.
Alternatively, you have to change the qmake.conf file for your MSVC compiler and rebuild all of Qt5 from source. Anywhere that QString is used will probably be touched by this, so that means you probably can't just rebuild QtCore where QString lives. (You would probably get link errors from all the other places in Qt that use QString, because the linker would be looking for QString::fromStdWString() and QString::toStdWString() with different arguments).
Who had the stupid idea that "Eh, it won't affect anyone if we change this flag, and we don't need to tell them or document it anywhere in the change notes"?
@d_stranz Bro you saved me from hell