I have qt project proj1 which depends on another (proj2).
Directory tree is like this:
common/
`--/pr1/
proj1.pri
main.cpp
`--/pr2/
proj2.pri
src1.cpp
src2.cpp
proj1 includes proj2:
include(../proj2.pri)
while in proj2.pri sources are listed as they are in current (pr2) dir:
SOURCES += src1.cpp \
src2.cpp
So when I try to build proj1 I'm getting such error:
make: *** No rule to make target `src1.cpp', needed by `src1.o'. Stop.
Is there any correct way to include subproject's sources (I need to do so for debugging) with help of pri-files ?
In proj1.pri, before including proj2.pri:
PROJECT_ONE_IS_DEFINED = 1
In proj2.pri:
isEmpty(PROJECT_ONE_IS_DEFINED){
DEPENDPATH += pr2
INCLUDEPATH += pr2
} !isEmpty(PROJECT_ONE_IS_DEFINED){
DEPENDPATH += ..\pr2
INCLUDEPATH += ..\pr2
}
This way project 2 will be included normally if used by itself, and will be included properly if used as part of project 1....
Or, you can simply add path to pr2 to DEPENDPATH in project1, as long as path to your cpp files is added to dependpath, make will work fine
EDIT:
The most efficient way that allows to include .pri file in many projects without worrying about specific path for each case is to add
DEPENDPATH += $$PWD
INCLUDEPATH += $$PWD
in the beginning of each .pri file.
Related
I have a Qt project. I can add some libraries using the commands like:
LIBS += -lopencv_core
They work perfectly for me. However, if I check the output, I have there other libraries, too. For example /usr/lib64, without mentioning this anywhere in the project. How can I avoid that addition?
You can explicity remove these paths. For example, I use that to remove all standard path (lib and includes) :
unix {
LIBS -= -L/usr/lib/
LIBS -= -L/usr/lib64/
LIBS -= -L/usr/lib
LIBS -= -L/usr/lib64
INCLUDEPATH -= /usr/include/
INCLUDEPATH -= /usr/include
}
In my .pro file in Qt project, I have used these two lines for adding necessary LIBS.
LIBS += -L "../../lib/bin/libname.a"
LIBS += -L "../../rfm2g/winver/libname.lib"
error: ../../rfm2g/winver/libname.lib: No such file or directory
The compiler found the file libname.a, but could not find the libname.lib, although the relative path for both files is correct. Does anybody have an idea?
The -L option wants a directory for -l to search, not the path to the actual library.
So you should either write e.g.
LIBS += -L../../lib/bin -lname
LIBS += -L../../rfm2g/winver -lothername
Or link with them directly
LIBS += ../../lib/libname.a
LIBS += ../../rfm2g/winver/libname.lib
Also make sure that the paths actually are correct. If you change to the build directory, and try to list the files (using ls or dir depending on platform) using the paths you have, can you list both files?
I have installed qt-opensource-windows-x86-msvc2013_64_opengl-5.4.0.exe and compiled boost_1_58_0.zip with this command: b2 toolset=msvc --build-type=complete stage. It works fine with Visual Studio, but when I try use it with Qt I get this error:
:-1: error: LNK1104: cannot open file 'libboost_filesystem-vc120-mt-gd-1_58.lib'
Here is my .pro file:
TEMPLATE = app
QT += qml quick widgets
SOURCES += main.cpp \
testclass.cpp
RESOURCES += qml.qrc
INCLUDEPATH += C:\boost
LIBS += "-LC:\boost\stage\lib\libboost_filesystem-vc120-mt-gd-1_58.lib"
#Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
testclass.h
In the LIBS variable use just "-L" for correct library path (-L). You made a mix, specifying a file (lowercase l) while libs directory is missing.
You do not need to specify the library, boost has pragmas for that.
I've made a C++/OpenGL application using the Qt framework, but I cannot to run *.exe file. I always get errors with libwinpthread-1.
I already read articles about that, but all dll's are in the Qt folder, so I don't understand what the problem is. Please take a look at my *.pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
sliceobj.cpp
unix|win32: LIBS += -lOPENGL32
unix|win32: LIBS += -L$$PWD/../../../../5.0.2/mingw47_32/lib/ -lglut32
QMAKE_LFLAGS += -static-libgcc -static-libstdc++
QMAKE_CXXFLAGS_WARN_ON += -Wno-unknown-pragmas
INCLUDEPATH += $$PWD/../../../../5.0.2/mingw47_32/include
win32 {
message("* Using settings for windows")
INCLUDEPATH += "C:\\opencv\\build\\include" \
"C:\\opencv\\build\\include\\opencv" \
"C:\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\opencv\\build\\x86\\vc11\\bin" \
-lopencv_core247\
-lopencv_highgui247\
-lopencv_imgproc247\
-lopencv_video247\
LIBS += -L"C:\\opencv\\build\\x86\\vc11\\staticlib" \
-lopencv_core247\
-lopencv_highgui247\
-lopencv_imgproc247\
-lopencv_video247\
}
Use Dependency Walker to see what exactly your code links against + Which libraries are loaded in runtime. Open your executable with DW and you will see DLL's that are linked against. They need to be present in PATH or beside your executable. Press F7 to start profiling to see which libraries are loaded in runtime. Here as snapshot:
Ok, i know that's not good, but i'm just added this files into debug directory .
I have a codebase where there are some shared libraries. For example LIB1 does some sort of processing that APP1 needs (depends on).
The qmake *.pro files are setup like the following. There is one root *.pro that is a TEMPLATE=subdirs that lists APP1 and LIB1 as it's subdirs.
LIB1.pro:
TARGET = LIB1
TEMPLATE = lib
QT += core
QT += xml
DESTDIR = path/to/libs/directory
SOURCES += \
File1.cpp \
FileN.cpp
HEADERS += \
File1.h \
FileN.h
APP1.pro:
#------ dependencies ------#
LIBS += -Lpath/to/libs/directory
# LIB1
INCLUDEPATH += path/to/libs/directory/LIB1lib
DEPENDPATH += path/to/libs/directory/LIB1lib
LIBS += -lLIB1
HEADERS = \
FileNplus1.h \
FileM.h
SOURCES = \
FileNplus1.cpp \
FileM.cpp
The problem is that when you compile the root *.pro file LIB1 will compile but APP1 fails to compile with the error QDomElement: No such file or directory because APP1.pro doesn't have QT += xml.
There is a hack that I use but I would like to overcome this hack. The hack involves adding the following line to APP1.pro:
# add this to APP1.pro... let's it compile again
QT += xml
Is there anyway to setup your qmake *.pro files such that, APP1.pro depends on LIB1 without needing to modify APP1.pro to add the QT += xml?
(The reason for this question is let's say you have other libraries that depend on other stuff... I would like to have Qt/Qmake take care of the dependencies like for example the Qt += xml dependency.)
qmake allows you to create your own configuration features. (last paragraph)
So you can create your own feature and move your lib1-linking code to it. You can add QT+=xml here. And in app.pro you'll just write CONFIG += lib1