building a Qt application outside the Qt sourcetree - qt

I made a simple Qt application that's based on an Qt example application and builds fine from within the "examples" directory of the Qt sourcetree.
Now I want to move my project files to a different location but qmake fails to create a Makefile that can find the Qt header files.
The project files have been moved from ~/qt-everywhere-opensource-src-4.7.2/examples/webkit/fullscreenbrowser to ~/cvswork/fullscreenbrowser/
So the .pro file is now ~/cvswork/fullscreenbrowser/fullscreenbrowser.pro
And the Qt sources are still at ~/qt-everywhere-opensource-src-4.7.2
qmake itself runs fine, but make fails to load some includes:
$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_WEBKIT_LIB
-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB
-I/usr/share/qt4/mkspecs/linux-g++
-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork
-I/usr/include/qt4/QtGui
-I/usr/include/qt4/QtWebKit
-I/usr/include/qt4
-I.
-o main.o main.cpp
main.cpp:41:17: error: QtGui: No such file or directory
For comparison, when building under the ...examples... directory, the first g++ call is much different:
$ make
g++ -c -pipe -fno-exceptions -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG
-DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX
-DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_HAVE_SSE3
-DQT_HAVE_SSSE3 -DQT_HAVE_SSE4_1 -DQT_HAVE_SSE4_2 -DQT_HAVE_AVX -DQT_SHARED
-I../../../mkspecs/qws/linux-x86-g++
-I.
-I../../../include/QtCore
-I../../../include/QtNetwork
-I../../../include/QtGui
-I../../../include/QtWebKit
-I../../../include
-I.moc/release-shared-emb-x86
-o .obj/release-shared-emb-x86/main.o main.cpp
What do i have to configure so that the Qt source directory is found?
EDIT: The fullscreenbrowser.pro file can be seen here: http://pastebin.com/jUPJiWBC
EDIT2: I get the same behavior in the examples directory when adding -nocache to the qmake call.

That's actually more or less by design I think. Building inside the source folder needs to be a bit different than building against an installed tree, just to be able to do upgrades sanely for instance (prebuild everything in-place without referencing any existing build).
I believe that "trick" is done with a specific .qmake.cache file in the toplevel source folder (~/qt-everywhere-opensource-src-4.7.2 in your case) that is created when you configure the source tree (which happens to build qmake in there).
Try copying that file to your new build location (~/cvswork/fullscreenbrowser/ or ~/cvswork if you have other projects, it should look there too), and re-run qmake (making sure you use the one inside the Qt source directory).
This should work if you've simply configured the source tree.
Here's the first lines of that .qmake.cache file on my machine after having unpacked and configured an old Qt archive:
CONFIG += release shared dll largefile stl precompile_header mmx 3dnow sse sse2 sse3 ssse3 sse4_1 sse4_2 avx dylib create_prl link_prl depend_includepath fix_output_dirs QTDIR_build
QT_SOURCE_TREE = $$quote(/home/foo/src/qt-everywhere-opensource-src-4.7.3)
QT_BUILD_TREE = $$quote(/home/foo/src/qt-everywhere-opensource-src-4.7.3)
QT_BUILD_PARTS = libs tools examples demos docs translations
QMAKE_ABSOLUTE_SOURCE_ROOT = $$QT_SOURCE_TREE
QMAKE_MOC_SRC = $$QT_BUILD_TREE/src/moc
#local paths that cannot be queried from the QT_INSTALL_* properties while building QTDIR
QMAKE_MOC = $$QT_BUILD_TREE/bin/moc
QMAKE_UIC = $$QT_BUILD_TREE/bin/uic
QMAKE_UIC3 = $$QT_BUILD_TREE/bin/uic3
QMAKE_RCC = $$QT_BUILD_TREE/bin/rcc
QMAKE_QDBUSXML2CPP = $$QT_BUILD_TREE/bin/qdbusxml2cpp
QMAKE_INCDIR_QT = $$QT_BUILD_TREE/include
QMAKE_LIBDIR_QT = $$QT_BUILD_TREE/lib
QMAKE_LFLAGS = -Wl,-rpath-link,$$QT_BUILD_TREE/lib $$QMAKE_LFLAGS
QT_CFLAGS_PSQL = -I/usr/include/postgresql-8.4
QT_LFLAGS_PSQL = -L/usr/lib64/postgresql-8.4/lib64
QT_CFLAGS_MYSQL = -I/usr/include/mysql
QT_LFLAGS_MYSQL = -Wl,-O1 -Wl,--as-needed -rdynamic -L/usr/lib64/mysql -lmysqlclient_r -L/usr//lib64 -lz -lpthread -lcrypt -lnsl -lm -lpthread -L/usr/lib64/ -lssl -lcrypto
Q T_LFLAGS_ODBC = -lodbc
QMAKESPEC = $$QT_BUILD_TREE/mkspecs/linux-g++-64
...
As you can see, a lot of the fundamental qmake variables are overridden with that build tree prefix.
(Not sure why you don't simply install Qt somewhere in your home directory. You wouldn't have any of this pain, and you don't need root for that I think as long as the prefix is your own - haven't tried that in ages though, so YMMV.)

The example probably attempts to include a file from elsewhere in the hierarchy. For simple cases you can often generate a new project file as follows:
qmake -project # generate a project file using defaults
qmake # generate a makefile from the project file
make # build using the makefile
qmake will go through your directory recursively examining and including files. It's not smart enough to figure out everything, like every module you may need, but it does a good job on simple test projects. I usually do the above for all my spikes.

Related

gcc Compling and linking object file and source file at the same time

In a nutshell , the issue is I have some object file (say a.o , b.o ) and some source file (f.c and g.c)
I have to compile and link in a single step.
This is what I am doing but I don't think this is the write way atleast I should give something like -l or -L for linking
gcc -Wall -O0 -ggdb -fPIC a.o b.o f.c g.c -o executable
This is the correct way, -l is used to link to a library (for example, the ptheads library needs -lpthread) and -L is used to add directories to the directories in which the linker looks for library files.
There is nothing wrong with compiling the software this way.
Most build systems build files one at a time in order to avoid having to rebuild the object file in case the source file was not modified and the object file still exists. If you are fine with rebuilding code, then your approach is perfectly valid.

No such file or directory #include <QDebug>

Why I got an error:
I use Qt Creator. Version Qt 5.9.7 for Desktop
Output::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
23:02:13: Uruchamianie "/usr/bin/make"
g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../Kurs_STL_cpp0x -I. -I../../anaconda3/mkspecs/linux-g++ -o main.o ../Kurs_STL_cpp0x/main.cpp
../Kurs_STL_cpp0x/main.cpp:4:10: fatal error: Debug: No such file or directory
#include <Debug>
^~~~~~~
compilation terminated.
Makefile:627: recipe for target 'main.o' failed
make: *** [main.o] Error 1
23:02:13: Proces "/usr/bin/make" zakończył się kodem wyjściowym 2.
Błąd budowania / instalowania projektu Kurs_STL_cpp0x (zestaw narzędzi: Desktop)
Podczas wykonywania kroku "Make"
23:02:13: Czas trwania: 00:00.
When you select a non-Qt project, the generated *.pro file is configured to disable Qt (and you will not be able to include Qt files).
In *.pro file, remove the line CONFIG -= qt to enable Qt.
After that, you may need to include the different Qt modules (widgets, quick, etc.) by adding them to the env variable QT (the module core and gui should be enabled by default).
For example, to use the Qt Widgets and Qt Quick, you have to add QT += widgets quick
You can also disable useless modules by adding a line like QT -= gui

make can't find Qt headers when compiling project on the command line

I'm trying to compile a Qt Creator project on the command line. Here's what I did.
$ qmake
$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DALLOWSYNCING -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o main.o main.cpp
In file included from ./model/videostream.h:4:0,
from ./model/videostreamersession.h:4,
from view/videoplayerwindow.h:4,
from main.cpp:3:
./model/videoframe.h:5:18: fatal error: QImage: No such file or directory
compilation terminated.
make: *** [main.o] Error 1
It looks like make can't find the header files for Qt-related classes. How do I tell make where it can find them using an additional parameter or environment variable? I noticed some search paths are included by default, but in my environment they're located in /opt/QtSDK/Desktop/Qt/474/gcc/include/.
As requested, my PRO file. It was initially generated by Qt Creator so it's nothing out of the ordinary.
QT += core gui
TARGET = output
TEMPLATE = app
SOURCES += # Trimmed for brevity
HEADERS += # Trimmed for brevity
# Special build flags
DEFINES += ALLOWSYNCING
# These libraries are required for the program to operate
LIBS += -ljrtp -ljthread
CXXFLAGS="-I/opt/QtSDK/Desktop/Qt/474/gcc/include/" CFLAGS="-I/opt/QtSDK/Desktop/Qt/474/gcc/include/" LDFLAGS="/opt/QtSDK/Desktop/Qt/474/gcc/lib" make
However, you're probably on a mac I'm guessing.. In which case you should just export QT_DIR=/opt/QtSDK/Desktop/Qt/474/, and add /opt/QtSDK/Desktop/Qt/474/bin to your PATH and that should jiggle everything into place once qmake runs.

How to compile a Qt application through the command line with MinGW?

I have downloaded the latest Qt version for MinGW, and I have the correct MinGW version which is compatible with Qt. When I try to make the project, g++ is unable to find my source file even if it's in the same folder as the project file.
Those are the steps I followed (all project and source files are in T:\QtTest ):
T:\QtTest> qmake -project
T:\QtTest> qmake
T:\QtTest> make
And the output is this:
T:\QtTest> make
mingw32-make -f Makefile.Debug
mingw32-make1: Entering directory `T:/QtTest’
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I“c:\Qt\4.8.0\include\QtCore” -I“c:\Qt\4.8.0\include\QtGui” -I“c:\Qt\4.8.0\include” -I”.” -I“c:\Qt\4.8.0\include\ActiveQt” -I“debug” -I“c:\Qt\4.8.0\mkspecs\default” -o debug\main.o main.cpp
g++: main.cpp: no such file or directory
g++: no input files
mingw32-make1: *** [debug/main.o] Error 1
mingw32-make1: Leaving directory `T:/QtTest’
mingw32-make: *** [debug] Error 2
I have no idea why it can't find "main.cpp" file when it's in the same directory as the
project files. Even if I replace "main.cpp" with the full path ("T:\QtTest\main.cpp") it still won't find it. What am I doing wrong?
The following is my project structure:
(main.cpp is the only file that I wrote, all the others were generated by qmake)
T:\QtTest\main.cpp
T:\QtTest\Makefile
T:\QtTest\Makefile.debug
T:\QtTest\Makefile.release
T:\QtTest\QtTest.pro
T:\QtTest\debug\
T:\QtTest\release\
My g++ version is 4.4.0, which is the version suggested by the Qt installer and available for download in the same page as the Qt for MinGW installer.
Problem solved.
It had nothing to do with MinGW or Qt or the makefiles generated by qmake. I found it was caused solely by a custom entry in the Windows registry. I'm posting this solution for anyone who encounters the same problem:
Sometime ago I had created an entry in the Windows registry under HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor called Autorun, which makes CMD.exe start in a custom working directory, which was something I wanted to do (so I followed the steps detailed in this page about "How to change the default startup directory for Command Prompt": http://windowsxp.mvps.org/autoruncmd.htm).
Well, I completely neglected the CAUTION part in that page, which states that "Changing the current directory using Autorun value as mentioned in this article, might affect the functionality of batch scripts". Yes, shame on me.
So, if you have the same problem of being unable to make your Qt projects using qmake, and everything else looks OK in your project structure and makefiles, verify that you don't have something in the Windows registry which might change the startup directory for the command prompt.
Do you have MSYS installed? If sh.exe from MSYS is on the system path, it may conflict with the interpretation of windows style paths. Check the documentation here.
If that isn't the problem, then delete everything in your project folder except the source files and start over again with qmake -project. After that step, open the .pro file and verify that things look correct. For a very basic project, I get something like this:
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += widget.h
FORMS += widget.ui
SOURCES += main.cpp widget.cpp
The next two steps, running qmake and then make should work correctly. If not, there is nothing wrong with the steps you followed and there is something wrong with your system/environment.

Including a library in Qt, why isn't this working?

This seems like it should be really simple. I compiled a library in Qt (this newmat library), and produced the file libnewmat.a. Now I need to integrate this library into another project but I just can't get it to work.
I've tried a few different things with the LIBS variable in my .pro file including:
Win32:LIBS += libnewmat.a #library is in same directory as the project
Win32:LIBS += "C:/...path.../libnewmat.a"
Win32:LIBS += L"C:/...path..." -lnewmat
I've even tried using forward and back slashes in the path but it made no difference. I also include this check to make sure the library is actually found:
!exists(libnewmat.a) {
error("libnewmat.a does not exist")
}
So I know that isn't the problem. What I don't understand is that when i ctrl+f the compiler output (which displays the commands that qmake is using at the command line), I don't find any reference to the library. For some reason my LIBS variable isn't making any difference on the command line which is where I would expect it to be. Here is a sample of the compiler output where I would expect the library to be referenced if anyone would like to double check:
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\2009.02\qt\include\QtCore" -I"..\..\..\..\Qt\2009.02\qt\include\QtGui" -I"..\..\..\..\Qt\2009.02\qt\include\QtOpenGL" -I"..\..\..\..\Qt\2009.02\qt\include" -I"..\Visual Studio Projects\NewMatProj\newmat10" -I"..\..\..\..\Qt\2009.02\qt\include\ActiveQt" -I"debug" -I"." -I"..\..\..\..\Qt\2009.02\qt\mkspecs\win32-g++" -o debug\moc_Window.o debug\moc_Window.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\GLPractice.exe debug/main.o debug/GLWidget.o debug/Window.o debug/CGSWidget.o debug/moc_GLWidget.o debug/moc_Window.o -L"c:\Qt\2009.02\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtOpenGLd4 -lQtGuid4 -lQtCored4
I suspect there is something really simple that I'm missing here.
I'm using QtCreator on Windows Vista.
I think the scope conditions are case sensitive:
win32:LIBS += libnewmat.a # lowercase w
I've the very same problem. Isn't it possible to link to a static library from a static library? Anyhow if you make a shared library by removing CONFIG+=static from .pro file you avoid this problem.
Cheers,
H
u dont need a lot of libs in pro file. try this, it worked for me.
Win32:INCLUDEPATH += .
Win32:LIBS += "C:/...path.../libnewmat.a"
or
Win32:DEPENDPATH += .
Win32:LIBS += "C:/...path.../libnewmat.a"
Also libnewmat.a might be linux library.. normally windows libs have .lib extension.. not sure though..
-Arps

Resources