How to get the target directory in PRO file - c++

I am building an application in Debug mode, how to get the target directory in pro file.
I didnt explicitly mentioned the target directory using "DESTDIR"
CORE_API_PATH = $$PWD/../Bin
SEPARATOR = "/"
QT += core gui xml widgets printsupport svg
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Cinemas
TEMPLATE = app
RC_ICONS += cinemas-icon.ico
qtHaveModule(opengl) {
DEFINES += QT_OPENGL_SUPPORT
QT += opengl
}
LIBS += -lQt5Concurrent -lglu32 -lopengl32 -lglut32 -LC:\Qt\Qt5.3.2\Tools\mingw482_32\i686-w64-mingw32\lib\glut -LC:\Qt\Qt5.3.2\Tools\mingw482_32\i686-w64-mingw32\lib\glu32
win32:CONFIG(release, debug|release): LIBS += "$$quote($${CORE_API_PATH}/Release/CoreApi.dll)"
else:win32:CONFIG(debug, debug|release): LIBS += "$$quote($${CORE_API_PATH}/Debug/CoreApiD.dll)"
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/SSH/lib/ -lssh2
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/SSH/lib/ -lssh2
else:unix: LIBS += -L$$PWD/SSH/lib/ -lssh2
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/3rdparty/qwt/lib/ -lqwt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/3rdparty/qwt/lib/ -lqwtd
else:unix: LIBS += -L$$PWD/qwt/lib/ -libqwt
QT += concurrent network
CONFIG += c++11
RESOURCES += \
cinemasresource.qrc
FORMS += \
I want to copy the app.exe from the current folder to some other folder

On Windows you can use DLLDESTDIR variable which specifies where to copy the target dll or exe. Just add this to your .pro :
CONFIG(release, debug|release): DLLDESTDIR += $$PWD/../exec
On Linux you can use QMAKE_POST_LINK variable which contains the command to execute after linking the TARGET together. So it is like:
CONFIG(release, debug|release): QMAKE_POST_LINK += $$quote(cp project $$PWD/../exec)
Here project is the name of the target file which you provide by TARGET = project
These will copy the executable binary to a directory named exec one level upper than the program working directory. You can have your arbitrary path.

Related

Linking a lib file with a non-standard name in Qt

On Windows, I'm attempting to add an external DLL to my Qt project (via Qt Creator). I have the following generated artifacts I'm trying to reference:
target/debug/mylib.d
target/debug/mylib.dll
target/debug/mylib.dll.d
target/debug/mylib.dll.lib
Adding the library/dll generates the following entry in my .pro file:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/target/release/ -lmylib.dll
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/target/debug/ -lmylib.dll
INCLUDEPATH += $$PWD/target/debug
DEPENDPATH += $$PWD/target/debug
Qt is expecting "mylib.dll.lib" to be named "mylib.lib", so with the above configuration the build fails with the error:
error: LNK1104: cannot open file 'mylib.lib'
The build works correctly if I rename "mylib.dll.lib" to "mylib.lib", but I'd rather not introduce this extra step, if possible. The dll.lib suffix is generated by Rust/Cargo, and there aren't any plans to allow this to be configured.
After doing some research, I've tried a couple of different options, including referencing it in PRE_TARGETDEPS, but I can't make the LNK1104 error disappear. What am I missing?
I figured it out. The trick is to refer to the files directly (i.e. not using the -L / -l parameters), like this:
win32:CONFIG(release, debug|release): LIBS += $$PWD/target/release/mylib.dll.lib
else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/target/debug/mylib.dll.lib
win32:CONFIG(release, debug|release): LIBS += $$PWD/target/release/mylib.dll
else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/target/debug/mylib.dll

Refer to included libraries in Qt C++ Project

There is a high chance that this might get downvoted, but I am still posting this since I did not find the answer anywhere. I have added a Static External Library to my Project and this is how the MyApp.pro looks like at the moment:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release/ -lCommonLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release/ -lCommonLibd
else:unix: LIBS += -L$$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release/ -lCommonLib
INCLUDEPATH += $$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release
DEPENDPATH += $$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release/libCommonLib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release/libCommonLibd.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release/CommonLib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release/CommonLibd.lib
else:unix: PRE_TARGETDEPS += $$PWD/../common/build-CommonLib-Desktop_Qt_5_3_MSVC2012_OpenGL_32bit-Release/release/libCommonLib.a
However, I am still unsure as how to refer to the Library (and a specific header file in there) from a header file in my project. I tried doing #include<CommonLib/Test.h> but it does not recognize either CommonLib or CommonLib/Test.h.
Your INCLUDEPATH points to the build directory, while library headers are most likely in the directory with CommonLib sources.

Adding jsoncpp external library to my qt project : (symbol(s) not found for architecture x86_64)

I'm trying to add jasoncpp library to my C++ qt project.
I included the header, and linked (I think) the library but I get these errors:
"symbol(s) not found for architecture x86_64" and "linker command failed with exit code 1 (use -v to see invocation)".
The symbols not found are obviously the ones concerning jsoncpp library.
This is my makefile:
QT += core gui webkitwidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = JsonTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/release/ -ljson
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/debug/ -ljson
else:unix: LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/ -ljson
INCLUDEPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
DEPENDPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
I really don't know how to proceed so thanks in advance.
If you installed it using cmake, try this commands:
mkdir -p build/debug
cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../..
make
change
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/release/ -ljson
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/debug/ -ljson
else:unix: LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/ -ljson
INCLUDEPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
DEPENDPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
for this:
unix|win32: LIBS += -ljsoncpp
and ready to use jsoncpp

"cannot find -lQt5Core -lQt5Gui etc" when using other not related libraries

ISSUE SOLVED (scroll down)
Im on windows 7 and compilling with MinGW.
I made a new Qt application in QtCreator 3.01 (Qt 5.2.1). I compile it, the empty application window pops up everything is awesome. But as soon as i use any other library (like boost or gtest) im starting getting these errors when compiling
cannot find -lqtmain
cannot find -lQt5Widgets
cannot find -lQt5Gui
cannot find -lQt5Core
ld returned 1 exit status
This is my .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2014-04-19T14:17:24
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Thermovision
TEMPLATE = app
include(Model/Model.pri)
include(Controller/Controller.pri)
include(View/View.pri)
include(Interface/Interface.pri)
SOURCES += \
main.cpp
HEADERS += \
logdebug.h
FORMS +=
OTHER_FILES += \
Model/Model.pri \
View/View.pri \
Controller/Controller.pri \
Interface/Interface.pri \
Globals/zGlobals.pri
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
INCLUDEPATH += $$PWD/../../../../../../../MinGW/msys/1.0/local/include
DEPENDPATH += $$PWD/../../../../../../../MinGW/msys/1.0/local/include
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../Downloads/boost_1_54_0/boost_1_54_0/stage/lib/ -lboost_thread-mgw48-mt-1_54
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../Downloads/boost_1_54_0/boost_1_54_0/stage/lib/ -lboost_thread-mgw48-mt-1_54d
this is the main.cpp
#include <iostream>
#include <QApplication>
#include "View/form.h"
#include <boost/thread.hpp>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Form w;
w.show();
boost::thread b;
return a.exec();
}
when i comment usage of boost thread, the include and the part in .pro file responsible for finding boost thread library everything compiles again. Same when im trying to use gtest.
The odd thing is that I havent found any information regarding this issue anywhere on the internet :<
Can someone help me?
=================================================================================
[SOLVED]
ok so it seems qt wanted me to explicitly add the libraries into project. I used the built-in tool which generated the following output
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Core.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Cored.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Core.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Cored.lib
but im sure one can thin it down (im gonna stay with this)
Based on our comments and outcome, it seems that a quick solution is to add the libraries explicitly that you wish to use. It will generate something like this in the background, so basically using static libraries as opposed to dynamic:
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Core.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Cored.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Core.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Cored.lib
Alternatively, which I would personally suggest more is to add the following line for now in your project file to get this working with dynamic libraries rather than static to make your application binary go up to the hill:
LIBS += -L$$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/

"No rule to make target" error when adding an external library in Qt Creator

I am new in the world of Qt. I would like to add an external library of wxMSW-2.8.12 in Qt Creator. In order to do that, I right-clicked on my .pro file and clicked on "Add Library", then I select "External Library". I finally choose the Library file, click on "Static" for "Linkage".
This is what I got automatically from Qt Creator:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/ -lwxbase28ud_xml
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/ -lwxbase28ud_xmld
else:unix: LIBS += -L$$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/ -lwxbase28ud_xml
INCLUDEPATH += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib DEPENDPATH += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/libwxbase28ud_xml.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/libwxbase28ud_xmld.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/wxbase28ud_xml.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/wxbase28ud_xmld.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/libwxbase28ud_xml.a
But, when running, I get this error:
:-1: erreur : No rule to make target 'C:/Qt/Qt5.2.0/Tools/QtCreator/bin/testConverter/../../../../../../wxMSW-2.8.12/lib/vc_lib/libwxbase28ud_xmld.a', needed by 'debug\testConverter.exe'. Stop.
I tried to clean and rerun qmake but with any success.
Any suggestions?