Qmake 4.8.2 unresolved external symbol QSystemLocale

So, after updating my Qt version to 4.8.2 I encounter another compilation problems (as usual 😉 ).

As first, this is my linker output:

qlocale.obj : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QSystemLocale::query(enum QSystemLocale::QueryType,class QVariant)const " (?query@QSystemLocale@@UBE?AVQVariant@@W4QueryType@1@V2@@Z)
1>qlocale.obj : error LNK2001: unresolved external symbol "public: virtual class QLocale __thiscall QSystemLocale::fallbackLocale(void)const " (?fallbackLocale@QSystemLocale@@UBE?AVQLocale@@XZ)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString & __cdecl decimalForm(class QChar,class QChar,class QChar,class QString &,int,unsigned int,enum PrecisionMode,bool,bool)" (?decimalForm@@YAAAVQString@@VQChar@@00AAV1@HIW4PrecisionMode@@_N3@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString & __cdecl exponentForm(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,class QString &,int,unsigned int,enum PrecisionMode,bool)" (?exponentForm@@YAAAVQString@@VQChar@@00000AAV1@HIW4PrecisionMode@@_N@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "char * __cdecl qdtoa(double,int,int,int *,int *,char * *,char * *)" (?qdtoa@@YAPADNHHPAH0PAPAD1@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString __cdecl qulltoa(unsigned __int64,int,class QChar)" (?qulltoa@@YA?AVQString@@_KHVQChar@@@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::longLongToString(class QChar,class QChar,class QChar,class QChar,__int64,int,int,int,unsigned int)" (?longLongToString@QLocalePrivate@@SA?AVQString@@VQChar@@000_JHHHI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString __cdecl qlltoa(__int64,int,class QChar)" (?qlltoa@@YA?AVQString@@_JHVQChar@@@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::longLongToString(class QChar,class QChar,class QChar,class QChar,__int64,int,int,int,unsigned int)" (?longLongToString@QLocalePrivate@@SA?AVQString@@VQChar@@000_JHHHI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "bool __cdecl removeGroupSeparators(class QVarLengthArray<char,256> *)" (?removeGroupSeparators@@YA_NPAV?$QVarLengthArray@D$0BAA@@@@Z) referenced in function "public: bool __thiscall QLocalePrivate::numberToCLocale(class QString const &,enum QLocalePrivate::GroupSeparatorMode,class QVarLengthArray<char,256> *)const " (?numberToCLocale@QLocalePrivate@@QBE_NABVQString@@W4GroupSeparatorMode@1@PAV?$QVarLengthArray@D$0BAA@@@@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "double __cdecl qstrtod(char const *,char const * *,bool *)" (?qstrtod@@YANPBDPAPBDPA_N@Z) referenced in function "public: static double __cdecl QLocalePrivate::bytearrayToDouble(char const *,bool *,bool *)" (?bytearrayToDouble@QLocalePrivate@@SANPBDPA_N1@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "__int64 __cdecl qstrtoll(char const *,char const * *,int,bool *)" (?qstrtoll@@YA_JPBDPAPBDHPA_N@Z) referenced in function "public: static __int64 __cdecl QLocalePrivate::bytearrayToLongLong(char const *,int,bool *,bool *)" (?bytearrayToLongLong@QLocalePrivate@@SA_JPBDHPA_N1@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl qstrtoull(char const *,char const * *,int,bool *)" (?qstrtoull@@YA_KPBDPAPBDHPA_N@Z) referenced in function "public: static unsigned __int64 __cdecl QLocalePrivate::bytearrayToUnsLongLong(char const *,int,bool *)" (?bytearrayToUnsLongLong@QLocalePrivate@@SA_KPBDHPA_N@Z)
1>..\bin\\qmake.exe : fatal error LNK1120: 11 unresolved externals

The reason for this is missing two definitions in qmake.pri.

First is system-dependent qlocale_win.cpp / qlocale_unix.cpp. For fixing it you have to update these to files to unix{} and win32{}

 unix {
        SOURCES += qfilesystemengine_unix.cpp qfilesystemiterator_unix.cpp qfsfileengine_unix.cpp qlocale_unix.cpp #<<---- HERE
        mac {
          SOURCES += qfilesystemengine_mac.cpp
          SOURCES += qcore_mac.cpp qsettings_mac.cpp
          QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 #enables weak linking for 10.4 (exported)
          LIBS += -framework ApplicationServices
        }
    } else:win32 {
        SOURCES += qfilesystemengine_win.cpp qfsfileengine_win.cpp qfilesystemiterator_win.cpp qsettings_win.cpp \
            qsystemlibrary.cpp qlocale_win.cpp #<<--------- AND HERE
        win32-msvc*:LIBS += ole32.lib advapi32.lib
        win32-g++*:LIBS += -lole32 -luuid -ladvapi32 -lkernel32
    }

If you update .pri like this, you will gain another cute unresolved external:

qlocale.obj : error LNK2019: unresolved external symbol "class QString & __cdecl decimalForm(class QChar,class QChar,class QChar,class QString &,int,unsigned int,enum PrecisionMode,bool,bool)" (?decimalForm@@YAAAVQString@@VQChar@@00AAV1@HIW4PrecisionMode@@_N3@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString & __cdecl exponentForm(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,class QString &,int,unsigned int,enum PrecisionMode,bool)" (?exponentForm@@YAAAVQString@@VQChar@@00000AAV1@HIW4PrecisionMode@@_N@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "char * __cdecl qdtoa(double,int,int,int *,int *,char * *,char * *)" (?qdtoa@@YAPADNHHPAH0PAPAD1@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString __cdecl qulltoa(unsigned __int64,int,class QChar)" (?qulltoa@@YA?AVQString@@_KHVQChar@@@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::longLongToString(class QChar,class QChar,class QChar,class QChar,__int64,int,int,int,unsigned int)" (?longLongToString@QLocalePrivate@@SA?AVQString@@VQChar@@000_JHHHI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString __cdecl qlltoa(__int64,int,class QChar)" (?qlltoa@@YA?AVQString@@_JHVQChar@@@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::longLongToString(class QChar,class QChar,class QChar,class QChar,__int64,int,int,int,unsigned int)" (?longLongToString@QLocalePrivate@@SA?AVQString@@VQChar@@000_JHHHI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "bool __cdecl removeGroupSeparators(class QVarLengthArray<char,256> *)" (?removeGroupSeparators@@YA_NPAV?$QVarLengthArray@D$0BAA@@@@Z) referenced in function "public: bool __thiscall QLocalePrivate::numberToCLocale(class QString const &,enum QLocalePrivate::GroupSeparatorMode,class QVarLengthArray<char,256> *)const " (?numberToCLocale@QLocalePrivate@@QBE_NABVQString@@W4GroupSeparatorMode@1@PAV?$QVarLengthArray@D$0BAA@@@@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "double __cdecl qstrtod(char const *,char const * *,bool *)" (?qstrtod@@YANPBDPAPBDPA_N@Z) referenced in function "public: static double __cdecl QLocalePrivate::bytearrayToDouble(char const *,bool *,bool *)" (?bytearrayToDouble@QLocalePrivate@@SANPBDPA_N1@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "__int64 __cdecl qstrtoll(char const *,char const * *,int,bool *)" (?qstrtoll@@YA_JPBDPAPBDHPA_N@Z) referenced in function "public: static __int64 __cdecl QLocalePrivate::bytearrayToLongLong(char const *,int,bool *,bool *)" (?bytearrayToLongLong@QLocalePrivate@@SA_JPBDHPA_N1@Z)
1>qlocale_win.obj : error LNK2001: unresolved external symbol "__int64 __cdecl qstrtoll(char const *,char const * *,int,bool *)" (?qstrtoll@@YA_JPBDPAPBDHPA_N@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl qstrtoull(char const *,char const * *,int,bool *)" (?qstrtoull@@YA_KPBDPAPBDHPA_N@Z) referenced in function "public: static unsigned __int64 __cdecl QLocalePrivate::bytearrayToUnsLongLong(char const *,int,bool *)" (?bytearrayToUnsLongLong@QLocalePrivate@@SA_KPBDHPA_N@Z)
1>qlocale_win.obj : error LNK2001: unresolved external symbol "unsigned __int64 __cdecl qstrtoull(char const *,char const * *,int,bool *)" (?qstrtoull@@YA_KPBDPAPBDHPA_N@Z)
1>..\bin\\qmake.exe : fatal error LNK1120: 9 unresolved externals

Also this linker error is caused by missing file in SOURCE definition. In this case add qlocale_tools.cpp to SOURCE in bootstrap { #Qt code


bootstrap { #Qt code
   DEFINES+=QT_NODLL QT_NO_THREAD
   SOURCES+= \
        qbitarray.cpp \
        qbuffer.cpp \
        qbytearray.cpp \
        qbytearraymatcher.cpp \
        qcryptographichash.cpp \
        qdatetime.cpp \
        qdir.cpp \
        qdiriterator.cpp \
        qfile.cpp \
        qabstractfileengine.cpp \
        qfileinfo.cpp \
        qfilesystementry.cpp \
        qfilesystemengine.cpp \
        qfsfileengine.cpp \
        qfsfileengine_iterator.cpp \
        qglobal.cpp \
        qnumeric.cpp \
        qhash.cpp \
        qiodevice.cpp \
        qlist.cpp \
        qlinkedlist.cpp \
        qlocale.cpp \
        qlocale_tools.cpp \  #<< ----- HERE

Now re-call qmake and recompile it. Everything should works ok. The question is, why no-one in Qt didn’t find this error.

Qt application crash when compiled for 64-bit VS2010

Callstack

>	QtGui4.dll!00000000652f071f()
 	[Frames below may be incorrect and/or missing, no symbols loaded for QtGui4.dll]
 	QtGui4.dll!00000000652f07ae()
 	QtGui4.dll!0000000065326821()
 	QtGui4.dll!0000000065327f30()
 	QtGui4.dll!00000000653284ba()
 	QtGui4.dll!000000006532a5f5()
 	QtGui4.dll!00000000652f4792()
 	QtGui4.dll!000000006532f701()
 	QtGui4.dll!000000006535be71()
 	QtCore4.dll!0000000059a0ab9f()
 	QtGui4.dll!0000000065306eb9()
 	QtCore4.dll!00000000599f7903()
 	QtGui4.dll!0000000064eaffa2()
 	QtGui4.dll!0000000064eb2e56()
 	QtCore4.dll!00000000599f7792()
 	QtGui4.dll!0000000064eec2a3()
 	QtGui4.dll!0000000064eee85e()
 	QtGui4.dll!0000000064eec265()
 	QtGui4.dll!0000000064eee85e()
 	QtGui4.dll!0000000064eec265()
 	QtGui4.dll!0000000064eee85e()
 	QtGui4.dll!0000000064efa870()
 	QtGui4.dll!0000000065208727()
 	QtGui4.dll!000000006527a082()
 	QtGui4.dll!0000000064eaffb6()
 	QtGui4.dll!0000000064eb2e56()
 	QtCore4.dll!00000000599f7792()
 	QtGui4.dll!0000000064ef264c()
 	QtGui4.dll!0000000064ef26c7()
 	QtGui4.dll!0000000064ef26c7()
 	QtGui4.dll!0000000064ef26c7()
 	QtGui4.dll!0000000064efe30c()
 	OrmDesigner2.exe!000000013f95a2cf()
 	OrmDesigner2.exe!000000013f95dce2()
 	kernel32.dll!000000007794652d()
 	ntdll.dll!0000000077c8c521()

The bug is probably caused by wrong alignment or incorrect VS2010 compiler optimalization.

Found resources:
https://bugreports.qt.nokia.com//browse/QTBUG-11445
https://connect.microsoft.com/VisualStudio/feedback/details/573262/incorrect-alignment-with-x64-optimizer-and-movaps
http://support.microsoft.com/kb/2280741
https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=31433

Workarounds:

First way – Update VS2010 mkspec for Qt

go to $QTDIR/mkspecs/win32-msvc2010/qmake.conf and replace -02 with -01 (ie. reducing the optimzation level).Also /Ob0 could be used.

Microsoft hotfix for VS

http://archive.msdn.microsoft.com/KB2280741
File patch name VS10-KB2268081-x86.exe

Install Visual Studio 2010 SP1

Service pack could also contains required fix.
http://www.microsoft.com/download/en/details.aspx?id=23691

Problem with Qt compilation under Windows 64-bit

This short post will show you how to resolve following error during Qt compilation on 64-bit windows:

Creating library ..\..\..\..\lib\QtWebKitd4.lib and object ..\..\..\..\lib\Qt
WebKitd4.exp
PluginViewWin.obj : error LNK2019: unresolved external symbol _HBeginPaint refer
enced in function "private: static struct HDC__ * __cdecl WebCore::PluginView::h
ookedBeginPaint(struct HWND__ *,struct tagPAINTSTRUCT *)" (?hookedBeginPaint@Plu
ginView@WebCore@@CAPEAUHDC__@@PEAUHWND__@@PEAUtagP AINTSTRUCT@@@Z)
PluginViewWin.obj : error LNK2019: unresolved external symbol _HEndPaint referen
ced in function "private: static int __cdecl WebCore::PluginView::hookedEndPaint
(struct HWND__ *,struct tagPAINTSTRUCT const *)" (?hookedEndPaint@PluginView@Web
Core@@CAHPEAUHWND__@@PEBUtagPAINTSTRUCT@@@Z)
..\..\..\..\lib\QtWebKitd4.dll : fatal error LNK1120: 2 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\
VC\BIN\x86_amd64\link.EXE"' : return code '0x460'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\
VC\BIN\nmake.exe"' : return code '0x2'

This error is caused by bug in QMAKE_HOST variable used in WebCore.pro file. This variable is tested to determine destination platform (x86 or x64).
This variable contains x86 value also on 64-bit builds instead of x86_64 value. This value is tested on the following line in a WebCore.pro file:

win32:!win32-g++*:contains(QMAKE_HOST.arch, x86_64):{

If you want to fix this error, simply replace QMAKE_HOST by QMAKE_TARGET variable. Updated line should look like this:

win32:!win32-g++*:contains(QMAKE_TARGET.arch, x86_64):{

After this update all required asm defines are correctly included and build of WebKit will be successful.

Update for this error

In newer versions of Qt there is already applied fix the error with QMAKE_HOST / QMAKE_TARGET, but also there is a new problem ;-(.

The Problem is in the following “if” definition:

   if(win32-msvc2005|win32-msvc2008):equals(TEMPLATE_PREFIX, "vc") {
        SOURCES += \
            plugins/win/PaintHooks.asm
    }

When you compile your project for MSVC 2010, .asm file isn’t included. It’s necessary to add win32-msvc2010 to this definition. So updated WebCore.pro for Qt 4.8 will look like this:

 if(win32-msvc2005|win32-msvc2008|win32-msvc2010):equals(TEMPLATE_PREFIX, "vc") {
        SOURCES += \
            plugins/win/PaintHooks.asm
    }

Next problem solution

Next problem which I found during compilation is wrongly set QMAKE_TARGET.arg. For unspecified reason, when I compile 64bit library in 64bit system in 64bit VS command line, this variable has value x86 instead of x86_64.
The problem is in the qmake project.cpp file. QMAKE trying to determine 64/32 bit version based on the %PATH% configuration. Qmake search for VS-PATH\bin\amd64 of \bin\x86_amd64 string. Unfortunately there is a bug in concating searched string. This is how looks original project.cpp file at line 3177:

QString vcBin64 = qgetenv("VCINSTALLDIR").append("\\bin\\amd64");
QString vcBinX86_64 = qgetenv("VCINSTALLDIR").append("\\bin\\x86_amd64");

The problem is, that VCINSTALLDIR contains \ at the end of the string, and then we append \ again. So, result is:

QString vcBin64 = qgetenv("VCINSTALLDIR");
if ( vcBin64.at( vcBin64.size()-1 ) != '\\' )
  vcBin64.append("\\");
vcBin64.append("bin\\amd64");

QString vcBinX86_64 = qgetenv("VCINSTALLDIR");
if ( vcBinX86_64.at( vcBinX86_64.size()-1 ) != '\\' )
  vcBinX86_64.append("\\");
vcBinX86_64.append("bin\\x86_amd64");

Now, QMake correctly determine 32/64 bit compilation and then correctly include PaintHooks.asm and your Qt WebCore will be sucesfully compiled.

Qt programming tips

How to configure mkspec for paralel builds on Windows

Edit qmake.conf file in Qt\mkspecs\win32-msvcXXXX. Add -MP2 / -MP4 to the following defines:

QMAKE_CFLAGS_RELEASE    = -O2 -MD -MP4
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi -MP4
QMAKE_CFLAGS_DEBUG      = -Zi -MDd -MP4

How to deploy Qt application on MacOs

Missing dylib libraries

If your application using some externals dynamic libraries (called .dylib in MacOs system), you have to provide all these libraries. The simplest way is to provide these libraries into the Application.app directory.

Find out which libraries are used

Qt provide really useful tool called “otool” which serves to lots of purpose. One of them is to detect which shared libraries are required by our application. For this purpose otool has parameter -L. The usage is following:

otool -L ./Test1.app/Contents/MacOS/Test1

Output could looks like this:

./Test1:
        libboost_iostreams.dylib (compatibility version 0.0.0, current version 0.0.0)
        libboost_filesystem.dylib (compatibility version 0.0.0, current version 0.0.0)
        libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
        libboost_thread.dylib (compatibility version 0.0.0, current version 0.0.0)
        libboost_date_time.dylib (compatibility version 0.0.0, current version 0.0.0)
        libboost_regex.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/dev/dev/SharedLibraries/libiconv/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.0.0)
        /Users/dev/dev/ExternalLibraries/../SharedLibraries/libxml/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.8.0)
        /Users/dev/dev/ExternalLibraries/../SharedLibraries/libxslt/lib/libxslt.1.dylib (compatibility version 3.0.0, current version 3.26.0)
        /Users/dev/dev/ExternalLibraries/../SharedLibraries/libxslt/lib/libexslt.0.dylib (compatibility version 9.0.0, current version 9.15.0)
        /Users/dev/dev/ExternalLibraries/yaml-cpp-0.2.5/build/libyaml-cpp.0.2.dylib (compatibility version 0.2.0, current version 0.2.5)
        QtGui.framework/Versions/4/QtGui (compatibility version 4.7.0, current version 4.7.0)
        QtCore.framework/Versions/4/QtCore (compatibility version 4.7.0, current version 4.7.0)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

Output from “otool” is simmilar to linux tool “ldd”.

The Mac Deployment Tool

Because manual copying and configuring all shared libraries to our application could be difficult, Qt have deployment tool which do all work for us. Tool is called “macdeployqt” and can be found in /Developer/Tools/Qt/macdeployqt.

 /Developer/Tools/Qt/macdeployqt ./GeneratedFilesMacOs/Debug/Test1.app

Note: Every time when you call macdeployqt tool, project have to be build from scratch. But is sufficient when whole result directory is removed and linked again:

rm -rf ./GeneratedFilesMacOs/Debug/Test1.app/
make

How to configure Linux for Qt programming.

How to configure script for automatic run after login

Create .bash_profile file in your home directory.

nano ~/.bash_profile

And enter following content to the new created file:

 # ~/.bash_profile
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

How to configure new search path

If you want to have bin folder in your home directory, enter following code snippet to your .bash_profile file:

PATH=$PATH;/Users/thomas/bin

Conclusion & Note

It’s possible that all of these task can be done in simpler way, or can’t be done at all. All comments and tips are based on my current experience with my first Linux configuration in my life 😉

How to configure MacOs for Qt programming.

How to configure script for automatic run after login

Create startup-script(or any other)file in your home directory. Then enter following command

nano startup-script
chmod 777 ./startup-script
sudo defaults write com.apple.loginwindow LoginHook /Users/thomas/.startup-script

Another solution is to create .bash_profile file, which is launched automatically by system.

or create

How to configure new search path

If you want to have bin folder in your home directory, enter following code snippet to your .profile file located in your home directory:

export PATH=$PATH:/Users/user_name/bin

Open file using:

nano ./.profile

Note:Path is separated by char “:”.

How to instal apt-get alternative for MacOS

Mac OS have apt-get alternative called “port“.

Additional notes

Realtek RTL81xx macOs version:

How to mount Windows drive from MacOs

As first, create some directory where you want to mount your shared drive

mkdir mnt
cd mnt
mkdir computer_d
mount -t smbfs //user_name:[email protected]/d computer_d

Conclusion & Note

It’s possible that all of these task can be done in simpler way, or can’t be done at all. All comments and tips are based on my current experience with my first MacOS configuration in my life 😉

Qt correct setup for QMAKESPEC, QTDIR and PATH

When you want to use different configurations for different platforms in your .pro file, it’s necessary to correctly setup three variables: QMAKESPEC, QTDIR and PATH.

Here is how to configure for different platforms:

Microsoft Windows:

In SystemPropertes -> Enviroment variables add/update following values:

QTDIR = P:\QT\4.7.0
PATH = %QTDIR%\bin
QMAKESPEC=%QTDIR%\mkspecs\win32-msvc2005
LANG = en_US

Unix Bourne shell: (not tested)

QMAKESPEC=/usr/local/qt/mkspecs/linux-g++
PATH=$PATH:/local/qmake/bin
export QMAKESPEC PATH</pre>

Unix C shell: (not tested)

setenv QMAKESPEC /usr/local/qt/mkspecs/linux-g++
setenv PATH $PATH:/local/qmake/bin</pre>

Note

You can optionally use LANG variable to setup QtCreator language.

Old qt 3.0 guide: http://doc.trolltech.com/3.0/qmake-guide.html
How to configure enviroment: http://doc.qt.nokia.com/4.0/qmake-environment-reference.html

Qt qmake enhancement – how to generate structure VS project

The problem

One of big disadvantage when creating Visual studio project from .pro files using qmake is missing support for hierachical folders. All files are stored in in four folders (filters) named “Source Files”, “Header Files”, “Generated Files” and “Form Files”. When you have large project, this arrangement is really hard to use.

Simple Solution

qmake has undocumented setting parameter “flat”. Using this switch, you can tell qmake to create filters in Visual studio dependent to directory structures of files. Only drawback of this solution is continuing sorting to “Source files”,”Header files”,…

So result of this solution will look like this:

To achieve this behaviour, only thing what have to be done is add following line to your .pro file:

CONFIG -= flat

Final solution

But what to do when you want to have all files stored together in structure dependent on directory structure? Only solution which I found is update qmake project for myself. This update is simply and here is what is need to be done:

Add new method initHeaderAndSourceFiles to file msvc_vcproj.cpp and .h with following content

void VcprojGenerator::initHeaderAndSourceFiles()
{
	vcProject.SourceFiles.Name = "Source And Header Files";
	vcProject.SourceFiles.Filter = "cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx;h;hpp;hxx;hm;inl;inc;xsd";
	vcProject.SourceFiles.Guid = _GUIDSourceFiles;

	vcProject.SourceFiles.addFiles(project->values("HEADERS"));
	vcProject.SourceFiles.addFiles(project->values("SOURCES"));
	if (usePCH) // Generated PCH cpp file
		vcProject.HeaderFiles.addFile(precompH);

	vcProject.SourceFiles.Project = this;
	vcProject.SourceFiles.Config = &(vcProject.Configuration);
	vcProject.SourceFiles.CustomBuild = none;
}

and update method VcprojGenerator::initProject() in msvc_vcproj.cpp file. Replace following two lines (currently located on line 762)

initSourceFiles();
initHeaderFiles();

with following code:

if ( project->isActiveConfig("grouped") == false ) {
	initSourceFiles();
	initHeaderFiles();
}
else {
	initHeaderAndSourceFiles();
}

Now you can add new flag “grouped” to your .pro file. After that, source and header files will be merged in the visual studio project tree.

CONFIG -= flat
CONFIG += grouped

And here is result screenshot:

First Qt attempts – qmake troubles

External links

qmake documentation: qmake tutorial.html
qmake variables: qmake variable reference

Generate vcproj from .pro file

Command line for generating Visual studio project file from Qt .pro file.

qmake -tp vc test.pro

Missing moc_*.cpp file

When some of moc file isn’t properly generated and getting following error:

c1xx : fatal error C1083: Cannot open source file: '.\debug\moc_xxx.cpp': No such file or directory

try following:
Select corresponding .h file (for moc_xxx.cpp select xxx.h) in a project tree and select Compile from context menu. If the file is marked as “up-to-date“, try to change something in this file and repeat a compilation. If in the output window will be “up-to-date” again, you found a problem.

Use context menu on the corresponding .h file, select properties and edit “Configuration properties |Custom build steps|General|Outputs” to any value (add some char to the end of value), confirm change by Ok button and then return value back to original (remove added char). After that, compilation on correspond file will be successfully performed.

Linux relevant tips

List of known issues and tips

This is list of all known issues and problems which we had to solve during our first Qt installation on Linux, Windows and Mac.

Known errors

Error: undefined interface

What to do when compilation of QT crash with message “Error: undefined interface”.
http://www.qtforum.org/article/31561/error-when-building-libraries.html
http://www.qtcentre.org/threads/26245-Qt-4.6-api/qscriptextensionplugin.h(43)-Error-Undefined-interface

make: g++: Command not found

it’s necessary to instal g++ support (sudo apt-get install g+)

Basic XLib functionality test failed!

it’s necessary to instal xlib(xorg??) support (sudo apt-get install xorg-dev)

*** [sub-corelib-make_default-ordered] Error 2

Probably mishmash on 32bit / 64bit  system and QT versions.

undefined reference to `QEventDispatcherGlib::versionSupported()’

Probably missing libglib2.0-dev on your system. (sudo apt-get install libglib2.0-dev).

Undefined reference to QSslSocket::*

Missing OpenSSL library on your system. (sudo apt-get install libssl-dev)

gtk/gtk.h: No such file or directory

Missing gtk package. (sudo apt-get install libgtk2.0-dev ). After that its necessary to update db (sudo updatedb).

if system can’t find file gtk/gtk.h because gtk is stored in gtk-2.0 directory, add -I (capitalised i) param to configure with gtk path:

./configure -opensource -I /usr/include/gtk-2.0

cups/cups.h: No such file or directory

install libcups2. (sudo apt-get install libcups2-dev)

gst/gst.h: No such file or directory

install gstreamer 0.10. (sudo apt-get install libgstreamer0.10-dev)

Missing Include/glibconfig.h

it’s because this file isn’t in /usr/include/glib-2.0, but in /usr/lib/glib-2.0. So you have to include also this /usr/lib path or copy file to include/glib-2.0

Hints and tips

How to create symbolic link to directory

create symbolic link using ln -nsf /usr/include/gtk-2.0/gtk /usr/include/gtk

Minimal required libraries

List of libraries required by Qt:

  • libfontconfig1-dev
  • libfreetype6-dev
  • libx11-dev
  • libxcursor-dev
  • libxext-dev
  • libxfixes-dev
  • libxft-dev
  • libxi-dev
  • libxrandr-dev
  • libxrender-dev

And other which are required by some modules of Qt:

To install all required on Linux, use following commands

sudo apt-get install libfontconfig1-dev libfreetype6-dev libx11-dev libxcursor-dev libxext-dev libxfixes-dev libxcups/cups.h: No such file or directory ft-dev libxi-dev libxrandr-dev libxrender-dev

sudo apt-get install bison flex libqt4-dev libqt4-opengl-dev libphonon-dev libicu-dev libsqlite3-dev libxext-dev libxrender-dev gperf libfontconfig1-dev libphonon-dev

If error doesn’t disappear after installing correct library

Sometimes it’s necessary to reconfigure Qt using make confclean

How to find where is missing header file located on disk

Use find /path -iname xxx.h command

How to find package which contains missing header file

use apt-file application with following syntax:

apt-file search gdk/gdk.h

Useful links about instalation Qt on linux

List of links about installation:
Building Qt on Linux

Qt configuration for succesfull build

This is currently my latest configure command to compile Qt on my Ubuntu 10.10.

Compilation fixes

This is necessary when search path for following libraries isn’t entered to configure.

sudo ln -nsf /usr/include/gstreamer-0.10/gst /usr/include/gst

Todo

Figure out how works pkg-config (pkg-config –cflags gstreamer-0.10)

Qt installation and configuration

This is our company step-by-step guide to install and configure Qt on our developer machines.

How to install Qt

Link to Qt download site: http://qt.nokia.com/downloads

Windows (VS2005)

Download VS 2008 distribution from download site. When 2008 distribution is downloaded, it’s necessary to reconfigure and rebuild it for VS 2005 using next steps.

Linux

Download linux/x11 distro from Qt page. Download 32/64bit distro package. Setup downloaded files as executables:

chmod +x qt-sdk-linux-x86-opensource-2009.01.bin
chmod +x qt-creator-linux-x86-opensource-1.0.0.bin

Install Qt sdk to default directory and begin with configuration.

MacOS

Download latest Qt SDK distribution and latest XCode developer pack from apple site. Then install both.

How to configure Qt

Qt configuration is done via Configure script/executable on all platforms.

Windows

Run “Start menu->Visual studio->Tools-> Visual studio command prompt”
Then go to “c:\Qt\Qt_Version\Qt” and run “configure” with additional params.

Our current configuration:

configure -debug-and-release -opensource -shared -platform win32-msvc2005 -incredibuild-xge -openssl

Clean configurations

run nmake confclean and nmake distclean to remove all previous version of QT compilations.

SSL support

For SSL Support add -openssl switch to configure.

Note!

: configure param HAVE TO be executed from Visual studio command prompt!

Linux

Enter Qt directory and enter following configure param:

./configure -opensource -I /usr/include/gtk-2.0 -L /usr/lib/gt-2.0 -I  /usr/include/gstreamer-0.10 -L /usr/lib/gstreamer-0.10 -I /usr/include/glib-2.0 -L /usr/lib/glib-2.0 -I /usr/include/libxml2 -fast

Clean configurations

run make confclean and then configure.

MacOS

How to compile Qt

Windows

Compile Qt using command prompt:

  • Run Visual studio command prompt.
  • And run nmake to build a whole library

Second option is open projects.sln located in p:/Qt/4.7.1/ using Visual Studio IDE  and compile it.

Linux

  • As first thing, use configure to setup Qt settings.
  • As next, run make to build a whole library
  • After a while when everything is compiled, use make install. This will install library to /usr/local/Trolltech/Qt-4.7.0

MacOS

Currently not tested, using default compilation.

How to compile application

When we have prepared Qt library, it’s time to compile our application.

MacOS

When using  qmake without additional params, qmake generate xcode project from .pro instad makefile for g++. To generate makefile, use following params:

qmake -spec macx-g++
make

Deploying application

Windows

Not testes.

External link: http://doc.trolltech.com/4.5/deployment-windows.html

Linux

Not testes.

MacOS

Not testes.