qmake adding header files from subfolders - c++

I am trying to generate a c++ project using qmake and compiling it under visual studio.
this project as a dependency to itk.
I made a .pri with a MyITK project in it:
MyITK {
CONFIG_FOUND += MyITK
INCLUDEPATH += $${PACKAGE_SOURCES}/Shared/MyITK
QMAKE_LIBDIR += $${PACKAGE_LIB}/MyITK
win32:LIBS += ITKIONIFTI-4.13.lib \
ITKCommon-4.13.lib \
ITKBiasCorrection-4.13.lib \
ITKBioCell-4.13.lib \
etc
in the .pro of my project is like that:
CONFIG += staticlib MyITK
HEADERS += \
myowncode.h \
myowncode2.h \
myowncode3.h \
SOURCES += \
myowncode.cpp \
myowncode2.cpp \
when I try to compile my project, it find the .h only if I put them directly in $${PACKAGE_SOURCES}/Shared/MyITK
if I "copy past" the source code form itk, which is organized like that:
/Modules/ModuleNames/SubModulesNames/include
is there a way to make QMake looking for .h in all subdirectories ?
according to Matt answers I tried:
ITKModules = Core Filtering IO Numerics Registration Segmentation
Core.submodules = Common FiniteDifference
IO.submodules = NIFTI ImageBase
Numerics.submodules = Eigen FEM NarrowBand NeuralNetworks
Registration.submodules = Common FEM
Segmentation.submodules = BioCell ConnectedComponents KLMRegionGrowing
MyITK {
CONFIG_FOUND += MyITK
for(foo, ITKModules): for(bar, $${foo}.submodules) {
INCLUDEPATH += $${PACKAGE_SOURCES}/Shared/MyITK/Modules/$${foo}/$${bar}/include
}
QMAKE_LIBDIR += $${PACKAGE_LIB}/MyITK
win32:LIBS += ITKIONIFTI-4.13.lib \
ITKCommon-4.13.lib \
ITKBiasCorrection-4.13.lib \
ITKBioCell-4.13.lib \
}
but it still can't link to the .h at VS compilation.

is there a way to make QMake looking for .h in all subdirectories ?
Actually you're trying to make your compiler look into all subdirectories, not qmake.
qmake itself has no built-in function to generate subdirs list. But you can prettify your pro a bit using loops:
modules = x1 x2 x3
x1.submodules = y1 y4
x2.submodules = y2 y5
x3.submodules = y3 y6
for(foo, modules): for(bar, $${foo}.submodules) {
INCLUDEPATH += /Modules/$${foo}/$${bar}/include
}

Related

How to add PoDoFo external library to my C++ project in Qt Creator?

I am using Qt Creator, Qt6, C++ for my program.
I would like to use the PoDoFo library but I have no knowledge of how to add the library/headers so that I can use it in my project and build it.
I have downloaded the PoDoFo code, just can't find any guidance/tutorials on how to add PoDoFo specifically in Qt Creator.
Edit: I tried "Add Library" to my project and used external library option. Once I finish, I try to compile my code and I get an error "podofo-0.9.7\COPYING.LIB:-1: error: LNK1107: invalid or corrupt file: cannot read at 0x62DC"
I can include the podofo.h file but that will also throw this error:"podofo-0.9.7\src\podofo\base\PdfCompilerCompat.h:44: error: C1083: Cannot open include file: 'podofo_config.h': No such file or directory"
.pro file:
QT += core gui sql printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
#QMAKE_CXXFLAGS += -std=c++17
SOURCES += \
addbookdialog.cpp \
addbooksdialog.cpp \
bookdetailswindow.cpp \
bulkdetailsdialog.cpp \
cleanebooksdialog.cpp \
insertlinkdialog.cpp \
inserttabledialog.cpp \
linkcollectiondialog.cpp \
linkmanagerwindow.cpp \
main.cpp \
mainwindow.cpp \
searchnamedialog.cpp \
summarywindow.cpp
HEADERS += \
addbookdialog.h \
addbooksdialog.h \
bookdetailswindow.h \
bulkdetailsdialog.h \
cleanebooksdialog.h \
common.h \
insertlinkdialog.h \
inserttabledialog.h \
linkcollectiondialog.h \
linkmanagerwindow.h \
mainwindow.h \
queries.h \
searchnamedialog.h \
summarywindow.h
FORMS += \
addbookdialog.ui \
addbooksdialog.ui \
bookdetailswindow.ui \
bulkdetailsdialog.ui \
cleanebooksdialog.ui \
insertlinkdialog.ui \
inserttabledialog.ui \
linkcollectiondialog.ui \
linkmanagerwindow.ui \
mainwindow.ui \
searchnamedialog.ui \
summarywindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
DISTFILES += \
style.qss
RESOURCES += \
images.qrc \
style.qrc
unix|win32: LIBS += -L$$PWD/3rdparty/podofo-0.9.7/ -lCOPYING
INCLUDEPATH += $$PWD/3rdparty/podofo-0.9.7/src/podofo
DEPENDPATH += $$PWD/3rdparty/podofo-0.9.7/src/podofo
qt creator add library dialog:
Did you take a look on this link: https://doc.qt.io/qt-5/third-party-libraries.html?
I just followed it and my 3rdParty library (https://github.com/cutelyst/simple-mail) was linked and accessible from my application C++.
Basically, your .pro file will look like this after setting everything properly:
TARGET = MyQtApp
TEMPLATE = app
INCLUDEPATH += 3rdparty/CatWhisperer/include
SOURCES += src/main.cpp
LIBS += -L"3rdparty/CatWhisperer/lib" -lCatWhisperer

How to link external DLLs properly in Qt creator

Am trying to build the project found # uconfig
, the project requires poppler and the author provided pre-built links
headers and DLLS
I have downloaded them and this is structure of the project
dll folder contains all the DLLS and poppler contains header files,
the pdf_extract.pro has the following content
QT += core gui widgets xml
TARGET = pdf_extract
TEMPLATE = lib
DEFINES += DATASHEET_EXTRACTOR_EXPORT_LIB
DESTDIR = "$$PWD/../../bin"
CONFIG(release, debug|release) {
CONFIG += optimize_full
}
SOURCES += \
$$PWD/datasheet.cpp \
$$PWD/datasheetpackage.cpp \
$$PWD/datasheetpin.cpp \
$$PWD/datasheetbox.cpp \
$$PWD/pdfdebugwidget/pdfdebugwidget.cpp \
$$PWD/pdfdebugwidget/pdfdebugviewer.cpp \
$$PWD/pdfdebugwidget/pdfdebugscene.cpp \
$$PWD/pdfdebugwidget/pdfdebugitempage.cpp \
$$PWD/pdfdebugwidget/pdfdebugitempin.cpp \
$$PWD/pdfdebugwidget/pdfdebugitemtextbox.cpp \
$$PWD/model/pdfdatasheet.cpp \
$$PWD/model/pdfpage.cpp \
$$PWD/model/pdftextbox.cpp \
$$PWD/model/pdfpin.cpp \
$$PWD/model/pdfcomponent.cpp \
$$PWD/controller/pdfloader.cpp
HEADERS += \
$$PWD/pdf_extract_common.h \
$$PWD/datasheet.h \
$$PWD/datasheetpackage.h \
$$PWD/datasheetpin.h \
$$PWD/datasheetbox.h \
$$PWD/pdfdebugwidget/pdfdebugwidget.h \
$$PWD/pdfdebugwidget/pdfdebugviewer.h \
$$PWD/pdfdebugwidget/pdfdebugscene.h \
$$PWD/pdfdebugwidget/pdfdebugitempage.h \
$$PWD/pdfdebugwidget/pdfdebugitempin.h \
$$PWD/pdfdebugwidget/pdfdebugitemtextbox.h \
$$PWD/model/pdfdatasheet.h \
$$PWD/model/pdfpage.h \
$$PWD/model/pdftextbox.h \
$$PWD/model/pdfpin.h \
$$PWD/model/pdfcomponent.h \
$$PWD/controller/pdfloader.h
LIBS += -L"$$PWD/../../bin"
LIBS += -L"$$PWD/dll/jpeg62.dll"
LIBS += -L"$$PWD/dll/libfreetype-6.dll"
LIBS += -L"$$PWD/dll/libopenjp2.dll"
LIBS += -L"$$PWD/dll/libpng12.dll"
LIBS += -L"$$PWD/dll/libpoppler-80.dll"
LIBS += -L"$$PWD/dll/libpoppler-qt5.dll"
LIBS += -L"$$PWD/dll/libtiff3.dll"
LIBS += -L"$$PWD/dll/zlib1.dll"
INCLUDEPATH += $$PWD/../../
LIBS += -lkicad
macx {
LIBS += -L /usr/local/lib
INCLUDEPATH += /usr/local/include
}
yet when I try to build the project I get these errors... am not sure what am doing wrong or missing
According to qmake documentation, using unix standards to specify linked libraries will work on Windows, too. Anyway, instead of
LIBS += -L"$$PWD/dll/jpeg62.dll"
I would try
LIBS += "-L$$PWD/dll" - ljpeg62
or just use Windows style:
LIBS += $$PWD/dll/jpeg62.dll
2 years late but i've also been wondering,
#include <QLibrary>
place your *.dll in your Debug/Release folder. e.g:
build-test-Desktop_Qt_6_1_2_MinGW_64_bit-Debug/debug
now simply:
QLibrary lib("myLibrary.dll");
if (!lib.load())
qDebug() << lib.errorString();
if (lib.load())
qDebug() << "library loaded";
alternatively, rather than placing the DLL in debug folder you can set the location of the dll to
c:/path/to/dll/yourdll.dll

Prevent compiler from using system library by default

I have a Qt project using SQL calls. On windows it is using the system library here C:\Program Files (x86)\Windows Kits\8.1\Include\um and its working fine.
However, under Linux (Fedora 20 distribution), there are two availables libraries. sqlite in /usr/includes and libiodbc in /usr/include/libiodbc. And I would like to force QT/The compiler to use libiodbc.
Is there a way to prevent the inclusion of the sqlite header? Or to force the user to have the required headers to be included with a #include
At the moment, there is no #include about any of the header, I've tried to include the libiodbc, but it's still trying to use the sqlite
EDIT : I have found the -nostdinc++, but if I use it, the header that im actually including, for example #include <regex> is not found anymore
EDIT2 : the problematic header are sqltypes.h and sqlext.h
My .pro files
QT -= gui
TARGET = Internal
TEMPLATE = lib
DEFINES += INTERNAL_LIBRARY
CONFIG += c++11
include( ../LSoftware.pri )
SOURCES += \
InDbHandle.cpp \
InDbConnection.cpp \
InDbStatement.cpp \
InGenius.cpp
HEADERS += \
InDefs.h \
InDbHandle.h \
InDbConnection.h \
InDbStatement.h \
InGenius.h
LIBS += -L$$OUT_PWD/$$DESTDIR -lLTech
INCLUDEPATH += $$PWD/../LTech
INCLUDEPATH += $$PWD/../Common
unix {
target.path = /usr/lib
INSTALLS += target
}
and LSoftware.pri
DEFINES *= QT_USE_QSTRINGBUILDER
# Supposed to be there by default, but just to be safe.
CONFIG += precompile_header warn_on
CONFIG(release, debug|release) {
DESTDIR = ../Output/Release$$QMAKE_TARGET.arch
OBJECTS_DIR = Release$$QMAKE_TARGET.arch
}
CONFIG(debug, debug|release) {
DESTDIR = ../Output/Debug$$QMAKE_TARGET.arch
OBJECTS_DIR = Debug$$QMAKE_TARGET.arch
}
MOC_DIR = $$OBJECTS_DIR
RCC_DIR = $$OBJECTS_DIR
# Not documented but seems to work...
PRECOMPILED_DIR = $$OBJECTS_DIR
PRECOMPILED_HEADER = StdAfx.h
LTP_PRODUCTION {
DEFINES += LTP_PRODUCTION
}

How to integrate QT with novint falcon?

Novint falcon is integrated using the HDAL SDK on Visual Studio. I could not find any documentation online to install the SDK on QT. I tried to include the HDAl library and header files in my QT project. The .pro file looks like this.The error is
:-1: error: No rule to make target '../imagesegment/hdl.h', needed by 'debug/main.o'. Stop.
#-------------------------------------------------
#
# Project created by QtCreator 2014-11-04T14:24:33
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = imagesegment
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
haptics.cpp \
gshaptics.cpp \
main_dx9.cpp \
main_opengl.cpp \
StdAfx.cpp
HEADERS += \
hdl.h \
hdlConstants.h \
hdlErrors.h \
hdlExports.h \
hdlu.h \
hdluExports.h \
adll.h \
afuncs.h \
atypes.h \
avars.h \
glut.h \
haptics.h \
StdAfx.h \
Widget.h
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../Program Files/Novint/HDAL_SDK_2.1.3/lib/ -lhdl
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../Program Files/Novint/HDAL_SDK_2.1.3/lib/ -lhdld
INCLUDEPATH += $$PWD/../../../../Program Files/Novint/HDAL_SDK_2.1.3/include
DEPENDPATH += $$PWD/../../../../Program Files/Novint/HDAL_SDK_2.1.3/include
Figured it out. We need to add the header files and libs as mentioned in the qmake documentation on qt website. Try to save qt in a folder with 'no spaces' in it's path.
TEMPLATE = app
TARGET = cube4
QT += 3d
SOURCES = cubeview.cpp main.cpp \
haptics.cpp
HEADERS = cubeview.h \
haptics.h \
src/haptics.h \
src/adll.h \
src/afuncs.h \
src/atypes.h \
src/avars.h \
src/glut.h \
src/StdAfx.h \
hdl/hdl.h \
hdl/hdlConstants.h \
hdl/hdlErrors.h \
hdl/hdlExports.h \
hdlu/hdlu.h \
hdlu/hdluExports.h
HEADERS += \
Widget.h
RESOURCES = cube.qrc
CONFIG += exceptions
win32:LIBS += $$quote(C:/Program Files/Novint/HDAL_SDK_2.1.3/lib/hdl.lib)
INCLUDEPATH += $$quote("$$PWD/../../../../Program Files/Novint/HDAL_SDK_2.1.3/include/hdl")
INCLUDEPATH += $$quote("$$PWD/../../../../Program Files/Novint/HDAL_SDK_2.1.3/include/hdlu")
INCLUDEPATH += $$quote("$$PWD/../../../../Program Files/Novint/HDAL_SDK_2.1.3/examples/Basic/src")
win32: INCLUDEPATH +="C:/Program Files/Novint/HDAL_SDK_2.1.3/include"

Compilation Error in Qt

I am trying to break my large project into sub directories and run it as a single executable. But when I am executing the code it is giving me the following error:
qtmain_win.cpp:-1: error: undefined reference to `qMain(int, char**)'
collect2: ld returned 1 exit status
Can anyone please explain what is the reason behind these errors...
Thanks in advance!!!!
I have made a .pro file in which all the path to the subdirectories are included. Then each directory has its own .pro and .pri file with a directory which is common in all the directories. This directory is made as a lib. Then there is a main with main.pro and main.cpp. I am pasting all the three files here: Project's pro file:
# build all components recursive
TEMPLATE = subdirs
######## normal build process ########
#
# Make sure your Main.pro is in the last line to ensure correct linking!
#
SUBDIRS =D:/MultiFuncTester/Modes/Start/Build/Start.pro \
D:/MultiFuncTester/Modes/MainMenu/Build/MainMenu.pro \
D:/MultiFuncTester/Modes/Solar/Build/Solar.pro \
D:/MultiFuncTester/Modes/Main/Build/Main.pro\
CONFIG += ordered
Main.pro:
# ################ include pri file #################
!include("Main.pri"):error("Main.pri not found")
# ################ override some pri settings #################
TEMPLATE = app
TARGET = MultiFuncTester
CONFIG =-static
QT +=core\
gui\
# ################ own sources #################
INCLUDEPATH +=D:/MultiFuncTester/
SOURCES +=../Sources/Main.cpp
Project's pri file which is common in all directories made as a lib
######################
# common stuff for all components
######################
TEMPLATE = lib
CONFIG += static \
warn_on \
qt \
QT += gui \
core \
INCLUDEPATH +=D:/MultiFuncTester/Modes \
DEPENDPATH +=D:/MultiFuncTester/Modes \
CONFIG += debug_and_release
CONFIG += build_all
CONFIG(debug, debug|release) {
CONFIG_SUFFIX = dbg
} else {
CONFIG_SUFFIX = rel
DEFINES += QT_NO_DEBUG \
QT_NO_DEBUG_OUTPUT \
NDEBUG
CONFIG(gcov) {
QMAKE_CXXFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
QMAKE_LFLAGS_RELEASE += -fprofile-arcs
QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE += -O0
}
}
CONFIG(crosstgt) {
#To be able to build Target run qmake as follows:
qmake CONFIG+=crosstgt
CONFIG_SUFFIX = $${CONFIG_SUFFIX}_tgt
DEFINES += TARGET_BUILD
}
OBJECTS_DIR = obj_$${CONFIG_SUFFIX}
MOC_DIR = moc_$${CONFIG_SUFFIX}
DESTDIR = lib_$${CONFIG_SUFFIX}