Since 4.8.0 is out, I've reinstalled Qt, and now I want to use cmake too. To make cmake work, I remember having to add the mingw bin folder (QtSDK\Desktop\Qt\4.7.3) to PATH back in Qt4.7.3, so I guessed that there would be a similar folder in QtSDK\Desktop\Qt\4.8.0 now but this is not the case. My question is, does anybody else have experience with setting up Qt and cmake? I could use some help right now, as I've googled for a bit and was unable to find any ways to make cmake work.
When trying to build, I get this well known message:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
Could NOT find Qt4 (missing: QT_QMAKE_EXECUTABLE QT_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindQt4.cmake:1171 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:3 (find_package)
You just need to set the path to qmake in QT_QMAKE_EXECUTABLE, and then cmake can use qmake -query to find all the other paths it needs (similar to pkg-config on Linux).
Steps for building a project using Qt and CMake usually are:
Check out / create project source folder
Create build folder outside the project folder
Start Qt command prompt / cmd and cd into build folder e.g. cd build\project
Run cmake or cmake-gui passing path to source folder e.g. cmake-gui ..\..\source\project
Set any variables, such as QT_QMAKE_EXECUTABLE and CMAKE_BUILD_TYPE
Run your build tool, or run cmake --build .
So, I found out what was the problem, and I think I should have known before. I simply added C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\bin to my PATH variable. It may be useful to note that, in a default 4.8.0 install, qmake is located in C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\bin as opposed to C:\QtSDK\Desktop\Qt\4.7.3\mingw\bin in 4.7.3. Notice the difference; msvc2010 vs mingw. It's actually glaringly obvious, as msvc2010 was the only folder in that directory.
I didn't try skyhisi's answer as it was no longer needed, but I'm guessing that it's another correct (if not better) way to make cmake work.
Just ran into the same problem... Take a look into findQt4.cmake
FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake qmake4 qmake-qt4 qmake-mac PATHS
"[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin"
"[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin"
"[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\${qt_install_version};InstallDir]/bin"
$ENV{QTDIR}/bin
DOC "The qmake executable for the Qt installation to use")
You can either alter registry keys, or, I personally prefer deleting all those keys altogether and modify $ENV{QTDIR} variable. Good luck.
I had this problem for a slightly different reason. Maybe this will help someone else:
I uninstalled Qt 4.8.3 and then installed qt 4.8.4. Based on Slava's answer I discovered that CMake is getting the value of $(qt_install_version} from:
[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\DefaultVersion]
This was still set to 4.8.3 even though all the other registry entries were updated to 4.8.4. Changing the value of the DefaultVersion key to 4.8.4 fixed the problem for me.
I had the same problem and I solved providing the path to qmake,
QT_QMAKE_EXECUTABLE /opt/qt-4.8.7/bin/qmake
On Mac, while the binaries are saved in /usr/local/Trolltech/Qt-4.8.7/bin
the required qmake required as value of QT_QMAKE_EXECUTABLE is, for my OS, stored in the path /opt/qt-4.8.7/bin/qmake . Hope this help as well.
Related
I have installed the current Qt 5.8 inside a users home directory and now try to use it since three days. Cmake always uses the system wide Qt installation and kdevelop does the same. No CodeCompletion on the new stuff and so on...
I tried to install it system wide in /opt/Qt but nothing changed.
So can please anyone tell me what environment variables do I have to change to integrate the current Qt Version in my Development System?
Many Thanks
By the way - it is a kdevelop 5.0 running on a Debian Linux testing
From cmake does not find qt 5.1.1 question:
You need to set the CMAKE_MODULE_PATH to the Qt installation where the *.cmake files are located. This CMake variable is used to select which Qt installation to use for compiling. There is also a`CMAKE_PREFIX_PATH environment variable.
See http://doc.qt.io/qt-5/cmake-manual.html
The code completion: in project settings add to include paths something like:
/.../.../5.8/gcc_64/include/QtGui/
/.../.../5.8/gcc_64/include/QtCore/
/.../.../5.8/gcc_64/include/QtQuick/
...
Edit: The following is only correct for Qt4 and not for Qt5!
The default qt version found by cmake is the one assoziated with the qmake binary in your $PATH. Run which qmake in order to find out which one it is. It will probably be the system-wide one. The fastest way to coerce cmake into finding your custom version is then adding your Qt's bin folder to the $PATH as the first entry and running kdevelop from that command line: PATH=/opt/Qt/5.8/bin:$PATH kdevelop. Code completion should then also work, as AFAIK kdevelop uses the include folders evaluated by cmake for code completion.
You might want to consider switching to QtCreator, which fixes this problem by listing all Qt versions as "Kits" which you can select in the project settings.
I followed these instructions in the configuration of OpenCV SDK for using it in Qt Creator IDE, but I couldn't conclude point 6.5, due to configuration errors in Cmake-GUI. I setup the configuration in CMake of the compilers gcc and g++ contained in Qt folder for MinGW32, and all looks Ok. But when Cmake-GUI starts the process of build configuration it ends up saying
"Error in configuration process, project files may be invalid".
It can't find the following:
QT_QMAKE_EXECUTABLE;
Qt5Concurrent_DIR;
QT5Core_DIR;
QT5Gui_DIR;
QT5Test_DIR;
QT5Widgets_DIR.
After this issue I tried to go on with following points of configuration tutorial, without reaching the final instruction of mingw32-make install. I'm using the following versions of softwares: Qt 5.3.0, OpenCV 2.4.9, CMake 2.8.12.2. My OS is Windows 7.
How can I recover the missing Qt files in CMake configuration?
Is there an alternative way for configuring OpenCV with Qt (like using precompiled build of OpenCV libraries)?
You just need to indicate CMake the correct paths to each one. Click oh the path to browse and set each one individually:
QT_QMAKE_EXECUTABLE;
For this one, you need to search inside the Qt installation folder for the /bin directory. On it, you' ll find the qmake.exe. In my case it was C:/Qt/5.3/winrt_x64/bin/qmake.exe
All the following ones are in the Qt's /lib/cmake directory. In my case: C:/Qt/5.3/winrt_x64/lib/cmake :
Qt5Concurrent_DIR;
C:/Qt/5.3/winrt_x64/lib/cmake/Qt5Concurrent
QT5Core_DIR;
C:/Qt/5.3/winrt_x64/lib/cmake/Qt5Core
QT5Gui_DIR;
C:/Qt/5.3/winrt_x64/lib/cmake/Qt5Gui
QT5Test_DIR;
C:/Qt/5.3/winrt_x64/lib/cmake/Qt5Test
QT5Widgets_DIR.
C:/Qt/5.3/winrt_x64/lib/cmake/Qt5Widgets
Then click generate. It' ll show a new error and ask you for the QT5OpenGL_DIR. Just as before, show CMake the correct directory. In my case: C:/Qt/5.3/winrt_x64/lib/cmake/Qt5OpenGL. Finally, click Configure again, and then Generate, and now you're done creating the build files.
You have to specify the location of Qt manually by passing it as an argument for QT5Core_DIR. Qt5_DIR or CMAKE_PREFIX_PATH does also the trick.
Example
Given your Qt 5 is installed at /opt/selfcompiled/Qt5. When calling cmake, add the flag from above:
cmake -DQt5_DIR=/opt/selfcompiled/Qt5 <pathToSourceDir>
Once the Qt 5 directory is set and found by CMake, all the other variables related to Qt 5 should be found from there, too.
I am attempting to compile a software that I have built using Qt, ITK, VTK, using mingw32 on Windows 7. I have successfully done this on many computers, but I am having trouble on my laptop.
I made a mistake when I first installed Qt on this machine, in that I installed the "msvc2010" or visual studio verision of Qt. I had VS installed, and this is what it defaulted to, and I did not change it. Realizing my mistake, I uninstalled all traces of this Qt, and installed the Mingw32 version. The exact version I downloaded was: Qt libraries 4.8.3 for Windows (minGW 4.4, 317 MB)
I installed mingw32, installed qt, all nice and dandy, and now I am compiling my software. It builds beautifully, but during the linking stage I get the following nasty error:
mingw32-make[2]: *** No rule to make target 'C:/QtSDK/Desktop/Qt/4.8.1/msvc2010/
lib/QtOpenGL4.dll', needed by 'x.exe'. Stop.
CMakeFiles\Makefile2:62: recipe for target 'CMakeFiles/x.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/x.dir/all] Error 2
Makefile:74: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
Where x is the name of my project.
Note the make target: C:/QtSDK/Desktop/Qt/4.8.1/msvc2010/lib/QtOpenGL4.dll. This is NOT the correct place to look for the DLLs. It is looking at the lib location of my first installation of Qt. The QtSDK folder does not even exist anymore, the new version is under a different folder.
This is sadly also reflected in the link.txt under CMakeFiles that is generated in the build folder by cmake. One of the entries is:
C:\QtSDK\Desktop\Qt\4.8.1\msvc2010\lib\QtGui4.dll
along with many other DLLs.
Clearly, the problem is that Cmake is generating targets for the previous version of Qt.
How can I erase whatever ridiculous cache this is originating from, so that it does not do this? I have reinstalled Cmake, I have reinstalled Qt, I have done everything I can think of. I have verified that the Cmake variable are all pointing to the correct Qt folder (the other one does not exist, so no way we could get to the linking stage if they were incorrect).
Thank you so much.
EDIT:
I get this very pertinent warning, that has the wretched file path in it:
CMake Warning (dev) at CMakeLists.txt:22 (ADD_EXECUTABLE):
Policy CMP0003 should be set before this line. Add code such as
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
as early as possible but after the most recent call to
cmake_minimum_required or cmake_policy(VERSION). This warning appears
because target "x" links to some libraries for which the linker must
search:
comctl32, vfw32, ws2_32, wsock32, -lgdi32, opengl32
and other libraries with known full path:
C:/Qt/4.8.3/lib/libQtGui4.a
C:/ITK/lib/libitksys-4.1.dll.a
C:/VTK/bin/libQVTK.a
C:/QtSDK/Desktop/Qt/4.8.1/msvc2010/lib/QtOpenGL4.dll
CMake is adding directories in the second list to the linker search path in
case they are needed to find libraries from the first list (for backwards
compatibility with CMake 2.4). Set policy CMP0003 to OLD or NEW to enable
or disable this behavior explicitly. Run "cmake --help-policy CMP0003" for
more information.
This warning is for project developers. Use -Wno-dev to suppress it.
I added the "NEW" policy, and the warning went away, but I still have the same problem.
The problem turned out to be that I had installed VTK while I had the old Qt (configured for VS2010 installed). When I included VTK's libraries, it also included DLLs from Qt--but it was still pointing to the old Qt.
I reinstalled VTK, and we got past this step.
Try to regenerate cmake files, :
mingw32-make clean
cmake .
Short version: You need to delete your CMakeCache.txt file in your build directory.
Long version: Whenever CMake searches for external libraries/programes etc (eg. by FIND_LIBRARY which is called when searching for Qt, for example), it saves the result in the cache. On subsequent runs, it simply uses the cached value (if any) instead of searching for the libraries again. Therefore, you need to remove these cache entries so that CMake really searches for the libraries again. Simply delete the CMakeCache.txt and start over. If both versions are installed in parallel, make sure that QTDIR environment variable is set correctly and the path includes <QTDIR>/bin, as CMake relies on qmake to find the relevant libraries.
Note: If you don't want to delete the whole cache, deleting the Qt relevant variables should work, too.
cmake -U *QT_* .
should do the trick.
However, deleting the whole cache is the cleanest solution.
I have compiled qt in to /home/user/Software/qt-4.7.4 folder. Then Iset the path in .profile. I did the static built before to /home/user/Software/qt-4.7.4-static-build. For some reason even after updating the PATH env variable it is not changed to the new path and keep giving me the old qmake version.
I tried source command but it does help, also when I try qmake -version it shows me the old path. if I try qmake in a qt project obviously it gives me
QMAKESPEC has not been set, so configuration cannot be deduced.
Error processing project file: /home/user/testUI.pro
can someone help me to get qt running. I am using ubuntu linux 10.04 and
I think you have to update both the QT and QTMAKESPEC environment variables.
Alight After some head banging and consulting a few people I figured the solution my self. What I forget to mention was that I changed the name of the qt installation folder which is a BIG NO NO. Apparently qmake stores its path statically rather than using the path variable.
I was searching a lot through Qt forums and Google for the last few days, but I could not find any obvious answer to this question.
I found the -prefix option (not even documented on Windows) that can be supplied to configure to specify different install directory, but this is not clear separation of the sources and binaries at all, since the build is still done in the source directory and then the files needed for installation are copied to the install directoy. I tried this -prefix option, and came to some problems. (i.e It doesn't copy the .pdb files to the install directory.)
Then I found this link about doing shadow builds but it has the big limitation that the build dir must be at the same level as the source dir.
I'm guessing you didn't try make
install? So try that. It should
install Qt to a separate directory
away from the sources.
Are you saying that after I do configure, I should do nmake install instead just nmake? I know that nmake will process the generated makefiles from qmake and will place them in the source Qt dir, but what nmake install will exactly do i.e in which directory will install the files and how to specify the directory where the files will be installed.
Note that I already do this:
configure -prefix builddir -platform win32-msvc2005
nmake install
The effect of the above two lines was that qt was compiled in the source dir and not directly to my builddir specified with prefix. Then the compiled files were copied in my builddir. I was hoping for something that will build my Qt files directly to the build dir, cause this way I stil need 4 Gb space for my source dir during the compilation. Also the pdb files were not copied to my buildir which is another issue.
Basically, you just have to run configure.exe from your build directory. For example:
mkdir \qt\4.5.2-build
cd \qt\4.5.2-build
set PATH=%cd%\bin;%PATH%
\qt\4.5.2-sources\configure.exe -platform win32-msvc2005
Where sources are in \qt\4.5.2-sources, that would cause the build to go into \qt\4.5.2-build on the current drive.
Also, you must have perl in your PATH, ActiveState Perl is suggested.
I had not previously heard of this limitation where the build and source directories must be at the same level. If you hit this problem you could try working around it by creating a symbolic link (see mklink command).
IIRC on Windows, you have to do a sandbox install, you can't do the UNIX-typical "make install".
There are two options usually for building Qt, -prefix-install and -prefix /foo
You pick one, so if -prefix doesn't allow you to type make install, then I guess on Windows you have to use the -prefix-install route, which is a sandboxed install to the directory you extract Qt to.
I'm guessing you didn't try make install? So try that. It should install Qt to a separate directory away from the sources.
At least the problem with the missing include files (e.g. qscriptengine.h) may by solved by temporary adding \qt\4.5.2-sources\include\Qt to the include path.
I moved the shadow build out of my home folder to a folder in C: and it worked. I know it's weird, but that's what happened. I suspect it must be a bug in syncqt.