How to add specific flags to moc in a qmake project? - qt

I compile a Qt executable using qmake && make on the following project.pro file:
INCLUDEPATH *= ../../dependencies/boost
QT *= opengl xml
CONFIG *= qt opengl static
TARGET = myexe
HEADERS = Viewer.hpp MainWindow.hpp Inspector.hpp
SOURCES = main.cpp Viewer.cpp MainWindow.cpp Inspector.cpp
However, when compiling, moc chokes on a boost macro which it cannot parse. To work around this bug, I need to pass the flag -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED to moc, but I cannot manage to do so.
How to I edit my .pro file to pass a given flag to moc? (but not to g++, as QMAKE_CXXFLAGS does)

A bit hackish, but what about if you overwrite the moc compiler so that it includes the flag. In the .pro:
QMAKE_MOC = $$QMAKE_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED

In my code in header files I just have:
#ifndef Q_MOC_RUN
//Here we include Boost or Ogre headers with Macro
#endif
It works perfectly in Qt5 x64 and need not recompiling anything.

There is an update to this issue for boost 1.53, see the last post here:
We need to add -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION also.

For add specific flags to moc in a qmake project(qt5.2) need:
load(moc)
QMAKE_MOC += -DBOOST_INCLUDE_GUARD_GOES_HERE

The best way I found to do this is based on a comment on the accepted solution from David Faure:
QMAKE_MOC_OPTIONS += -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED
The other proposed methods that involve load(moc) and manipulating the QMAKE_MOC variable itself have an unfortunate side effect: they prevent qmake from automatically adding INCLUDEPATH variables (and maybe others) that would normally be on moc's command line, if INCLUDEPATH is set up after the call to load(moc).
This approach composes easier if you have your qmake configuration split up to multiple files; you don't need to ensure that the change to the moc command line comes after all INCLUDEPATH directories are set.

See for example the Qmake docs for variables which details
ten different variables in the QMAKE_CFLAGS_* pattern, and
ten different variables in the QMAKE_CXXFLAGS* pattern
and hence I would start with QMAKE_CXXFLAGS which is documented as:
QMAKE_CXXFLAGS
This variable contains the C++ compiler flags that are
used when building a project. The value of this variable is typically
handled by qmake or qmake.conf and rarely needs to be modified. The
flags specific to debug and release modes can be adjusted by modifying
the QMAKE_CXXFLAGS_DEBUG and QMAKE_CXXFLAGS_RELEASE variables,
respectively. Note: On the Symbian platform, this variable can be used
to pass architecture specific options to each compiler in the Symbian
build system. For example:
QMAKE_CXXFLAGS.CW += -O2
QMAKE_CXXFLAGS.ARMCC += -O0
For more information, see qmake Platform Notes.
So I'd start with
QMAKE_CXXFLAGS += -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED
which you can just add to your .pro file.

In case you are doing Ogre3D (OGRE 1.8.1 SDK for Visual C++ .Net 2010 (32-bit) ) then use QT5 32bit instead of the QT5 64bit version, it will pass.
Also consider this :
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED 1
#endif
I think it has been compiled (boost included) with 32bit thus i suppose i have to take src and recompile (using my 64bit) but thats another story where i wont go for now since OGRE 1.9 RC 1 SDK for Visual C++ .Net 2012 (64-bit) will be soon release on stable version.
Regards
EDIT 1 :
Downloaded Qt libraries 4.8.4 for Windows and configured my QT creator (the one coming with full QT5 and guess what …. Ogre3D is working like a charm when compiling on 4.8.4.
Qt 5.0.2 for Windows 32-bit (VS 2010, 485 MB)
Qt libraries 4.8.4 for Windows (VS 2010, 234 MB)
OGRE 1.8.1 SDK for Visual C++ .Net 2010 (32-bit)
I also mentionned it for who is interested here : http://qt-project.org/forums/viewreply/128660/

Related

Qt Deployment error 0xc0000007b on Windows

I have a Qt 5.12 Windows app. I'm using Qt Creator and Mingw 64 bit.
I've deployed the app by windeployqt.exe. When I start it, the app requires the libgcc_s_seh-1.dll file. After I paste it in the dir, I get the 0xc000007b error. I ran Dependency Walker and it gives me the following errors:
Error: At least one required implicit or forwarded dependency was not found.
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Error: A circular dependency was detected.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
This is my .pro file
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Control
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
QMAKE_LFLAGS += -static-libgcc
##CONFIG += c++11
##QMAKE_CXXFLAGS += -std=c++0x
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
Can someone help me? Thank you very much.
I had a similar problem in the past, but I am not pretty sure if it's the same reason because I was compiling with MVSC.
In my case, the application internally links with x86 dependency files. I did download and install x64 dependency files and link with x64 files.
Anyway, the old version of Dependency Walker doesn't know to skip 32-bit DLLs in PATH when processing a 64-bit EXE or DLL the way Windows does, so some errors are not really relevant. You may find more information in this post.
If the problem remains, try to avoid the usage of a static version of libgcc, acording to this post. It is not designed to be statically linked.
...
#QMAKE_LFLAGS += -static-libgcc
...
I got that error when the compiled app could not see the Qt dlls, so check your path. It could also be that it cannot find other gcc dll, like libwinpthread-1.dll.

Remove linkage to libs in qmake

I have qmake .pro file with dependency from webkit (QT += webkit). When qmake is executed and Makefile is generated, I see that it's linking to some additional libs, which was not connected explicitly in .pro file.
I would like to use newer version of some lib, and remove linkage to older version.
I have tried te following things:
Delete the Makefile
Add "LIBS -= -llibrary_name" in the end of .pro file
Generate Makefile with qmake but it does not work - linkage to older
version of lib is still present in Makefile.
Is it possible to remove linkage in current case?
You'd need to recompile your version of Qt to use the libraries you want. The information comes from the build configuration of the Qt version that you're using. Simply point Qt's configure to the relevant libraries you wish to override, build it, and use it to build your project. It will automatically pull in the newer libraries that you overrode.

How to compile a Qt app so that Microsoft's dll are not needed? [duplicate]

This question already has answers here:
How to build Qt 4.8/5.2 statically under VS2012, using the static MSVC runtime, with Windows XP support?
(2 answers)
Closed 7 years ago.
I've got a Qt application that I compile statically, i.e. in such a way that all the Qt DLLs are not needed at execution time.
However, my app still needs Microsoft's DLLs: specifically MSVCP100.DLL and MSVCR100.DLL. How can I compile my application so that these two DLL are not needed? Do I need to set some flag somewhere in .pro file? I'm a bit lost with Qt static compilation in general so any suggestion would be welcome.
The problem is, that with Qt, a number of command line options are added before the command line options that come from the qmake variables. The solution is to remove these variables.
This did the trick for me:
QMAKE_CFLAGS_RELEASE += /MT
QMAKE_CXXFLAGS_RELEASE += /MT
QMAKE_CFLAGS_RELEASE -= -MD
QMAKE_CXXFLAGS_RELEASE -= -MD
The option you want to remove must match exactly. E.g. /MD and -MD are treated as different options.
Thanks to stijn to remind me of that... I forgot that the linker flag is in the compiler settings in MSVS, so I didn't find them and thought it wasn't possible...
However, these lines should do the trick, as they tell the linker to use the Multithreaded statically linked runtime libraries:
QMAKE_CFLAGS_RELEASE += /MT
QMAKE_CXXFLAGS_RELEASE += /MT
QMAKE_CFLAGS_DEBUG += /MTd
QMAKE_CXXFLAGS_DEBUG += /MTd
You probabely won't be able to remove those dependencies, as these DLLs include the C/C++ runtime environment, like the STD functions and classes, and Windows specific functions (they further depend on kernel32.dll). So in order to remove those, you would require to statically link the entire C/C++ runtime and parts of the windows OS...
Anyway this won't matter, as these DLLs will be present on virtually every win pc out there.

Installing OpenGL for Qt

I just have installed Qt 4 on windows 7. I am now in a bit of a confusion
How do I get to install OpenGL so that it works with QT? Is there an installer for OpenGL?
Qt docs. say it has support for OpenGL, but when I include QTOpenGL and build, the compiler issues an error of "No such file or directory"
Thanks for the reply in advance!
Are you sure you followed this to the letter? You need to include <QtOpenGL> and set the QT += opengl option in your pro file.
What tool chain are you using? (Visual Studio, Qt Creator/g++) You need to specify somewhere in your project settings that you want to use the QtOpenGL module. This will result in a line in your .pro file similar to this:
QT = core gui opengl
This causes qmake to add the proper include path when invoking the compiler (I believe).
added the line QT += opengl to the .pro file

Libqxt under Qt Creator

I want to create a tiny app which needs global shortcuts. So, I have downloaded the current version of libqxt (0.5.1) and opened as a project in Qt Creator.
Libqxt compiles without problems in this way, so I thought that adding this in the tab Dependencies of my project it would get added automatically in the build, like Eclipse does with JAR libraries (I know that are different IDEs but it seems to be a common feature among them).
What happens? Qt Creator compiles qxt before my project, when needed, but when I want to include its headers Qt Creator keeps warning me that it cannot find them.
Probably I am missing the correct name of headers (I tried the headers showed in qxt documentation: http://doc.libqxt.org/0.5.0/classQxtGlobalShortcut.html)
By the way, I looked the code for global shortcuts and I think I can rip it out and use it in my app as is and I am going to credit qxt team and open the code of my app.
from the documentation
Add the following lines to your .pro file:
CONFIG += qxt
QXT += core gui
Note: While building the Qxt on Linux do not forget to do a sudo make install otherwise this little piece of magic may fail to work.
Qt Creator doesn't know how to expose different libraries to your projects. It's developer's duty. Dependency ensures only that mentioned projects are already built before building your main project.
Your real concern was using Qxt without proper installation. Assuming that configure have been run and libqxt have been built (using Qt Creator or manually via qmake+make), my solution is adding following snippet (with obvious QXT_DIR customization) to .pro file:
QXT_DIR = $${IN_PWD}/../libqxt-0.5.1
LIBS += -L$${QXT_DIR}/deploy/libs
INCLUDEPATH += $${QXT_DIR}/deploy/include
for(module, QXT) {
MODNAME = $$upper($$replace(module, "(.).*", "\1"))$$replace(module, "^.", "")
INCLUDEPATH += $${QXT_DIR}/deploy/include/Qxt$${MODNAME}
INCLUDEPATH += $${QXT_DIR}/src/$${module}
win32:CONFIG(debug, debug|release):MODNAME = $$join(MODNAME,,,d)
LIBS += -lQxt$${MODNAME}
}
Unfortunately I'm not sure whether it works in complex projects.
By default Qxt is built in release mode, but Qt Creator uses debug mode and it leads to broken binaries of projects depending on Qxt under Windows. You have to switch your project to release mode or build Qxt in debug mode (run configure -debug and rebuild Qxt).
Last thing: In Windows you won't be able to run your project from Qt Creator even if you successfully build it. You must copy needed Qwt*.dll files (use the d-suffix versions if you're in debug mode) from libqxt-0.5.1/deploy/libs to your_project/(release|debug) directory .

Resources