I am sorry if the question was already asked but after some research I couldn't find an answer. I want to copy the .exe of a project into a folder automatically.
I am using Qt creator 5.0.1 MSCV2010 and it always makes two outputs: release and debug.
For example, I want the /release/project.exe to be in /release/exec/project.exe.
I saw I can copy file like .dll with in a .pro with:
INSTALLS =
But it only work with files which already exist, or the .exe is generated after the compilation. I think I can specify this into:
projects settings->Build compilation->step Make : jom.exe in C:\path\to\project-release
But I don't know what argument is needed,
Regards
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.
add a custom build step with the command an parameters
for windows (assuming you are doing this for the release build):
xcopy
Release\<target.exe> path\to\destination\file.exe /Y
%{buildDir}
This should work. I couldn't find any variable that points the target_path. So I defined it:
### to copy target file to build folder
CONFIG(debug, debug|release) {
TARGET_PATH = $$OUT_PWD/debug
}
CONFIG(release, debug|release) {
TARGET_PATH = $$OUT_PWD/release
}
win32: QMAKE_POST_LINK += copy /y "$$shell_path($$TARGET_PATH/app_name.exe)" "$$shell_path($$PWD/../build/)"
unix: QMAKE_POST_LINK += cp "$$shell_path($$TARGET_PATH/app_name)" "$$shell_path($$PWD/../build/)"
Related
Let's talk about it in linux terms. I have a ".so" file. I want to make the executable dependent on it, look for it in the same directory. How do you do it through qmake? Or can this only be achieved through the use of QLibrary?
For example, when you have a ".so" file and want to use it in your project, in qmake you write:
LIBS += -L"path to the folder that contains your .so" -lSoName
But the path is hardcoded, as you can see, and I'm wondering what to write there to make the executable look for the ".so" in the same directory.
You use RPATH
You can configure your binary or library to find shared library (or dll) in current directory using RPATH directive that is emedded in the binary itself which the loader respects at runtime
1- Add the following in your .pro file
unix {
message("Adding RPATH to the app")
QMAKE_LFLAGS += -Wl,-rpath=\'\$$ORIGIN/\'
QMAKE_RPATH =
}
This will set RPATH of executable to current directory and your executable will first try to look for that .so in your current directory and then in standard directory (this process is explained here)
2- After you compile and create binary VERIFY that RPATH is set correctly
objdump -x <path/to/binary> |grep RPATH
it should say $ORIGIN
Compile time configuration:
CXXFLAGS += -L"/path/to/libmarylin.so/file" -lmarylin
There are a few ways to do it.
If the executable is going in the current directory, just do LIBS += -L$$(PWD) -lSoName.
If you're putting the executable into some other sub-directory, specified by some qmake variable like DESTDIR, use LIBS += -L$$(DESTDIR) (or whatever variable holds that directory).
Alternatively, you can add the directory with the executable to the runtime path of the executable, which gives the dynamic linker a list of directories to search for any unresolved libraries at runtime. This can be done with QMAKE_RPATHDIR += -L$$(PWD) and LIBS += -lSoName, which will tell the linker to look for unresolved libraries in the current directory where qmake is run.
Some operating systems may also include the current directory in the runtime search path for libraries by default, in which case just doing LIBS += -lSoName should be sufficient. That is platform-dependent, though, while the above solutions are not.
I have a TEMPLATE = subdirs project with 6 subprojects which build in specified order.
I would like to copy the output file of project1 (it's target) to some folder.
This folder is passed with LIBS += -L to project2 and project2 may use this file as a static library.
I found some .pro file commands to copy target files wherever but they are performed at deploy step. I need this to be done at build step. Precisely after project1 got built and before project2 build starts. And would be better if that will be some code that could be kept in .pro file.
Create DestDir.pri in folder, where all of your projects located.
Insert next code:
isEmpty(DESTDIR) {
CONFIG(debug, debug|release) {
DESTDIR=$$PWD/Build/Debug
}
CONFIG(release, debug|release) {
DESTDIR=$$PWD/Build/Release
}
}
Include DestDir.pri to each pro file:
include(../DestDir.pri)
You can change DESTDIR variable to your path or set this variable via qmake command line utils - in both cases this code will locate your artefacts to common folder.
I have found one more way to achieve that:
copydata.commands = $(COPY_FILE) $$OUT_PWD/$(TARGET0) ~/my_libs/
first.depends = $(first) copydata
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata
It allows to control what library file (.so, .so.1, .so.1.0, .so.1.0.0) is copied and seems to be crossplatform, so I'll left it here too.
But I'll use Milovidov's solution as less complicated in my project.
I'm building a project in Qt Creator, and while I don't care where the intermediate .obj files go it's important that the final executable be put in (and run from) a particular directory where the many dependency DLLs etc. are to be found.
So, in Qt Creator, I select the 'Shadow Build' option and specify the path to this directory.
What I always find, however, is that instead of being put into this directory, the final executable is always placed into
the_Directory_I_Actually_Want/debug
... which is no use to me because, when I then try to run or debug the program from within Qt Creator, it won't start because the DLLs that it depends on are all in the_Directory_I_Actually_Want and not in the /debug subdirectory.
I've tried setting DESTDIR within my .pro file to the the_Directory_I_Actually_Want, and I've tried setting TARGET within my .pro file to the_Directory_I_Actually_Want/projectName, and I've tried faddling around with the various options that are part of the 'kit' configuration, and nothing seems to let me have any control over this.
Is there a way of doing this, or am I going to have to change the rest of my build system around just for Qt Creator's benefit?
Three years later...
Just use:
CONFIG -= \
copy_dir_files \
debug_and_release \
debug_and_release_target
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.
I have two sub directories docroot and config in my Qt project. Files in these directories shall be copied to the build directory whenever I build / debug the project.
As of https://stackoverflow.com/a/3991210/356726 this is possible by using INSTALLS (QtDoc), which seems to be much easier than running copy command (e.g here). A similar approach is described here.
config.path = $${DESTDIR}/config
config.files = config/*
docroot.path = $${DESTDIR}/docroot
docroot.files = docroot/*
INSTALLS += config docroot
However, when I run a build in Qt Creator nothing happens. This here says I need to run make install . Can I somehow trigger / do this from within Qt Creator automatically whenever I build. I would need always the latest version of the files.
EDIT: Eventually I have used $$OUT_PWD instead of $$DESTDIR
Original comment from Logan here:
"Just a note: I used $$OUT_PWD instead of $$DESTDIR to make it work. For reference $$OUT_PWD is the folder that the program is built to, and $$PWD is the folder that the program is Being built from -in other words it's where the .pro file is."
What you need is a custom build step.
Switch to Projects Mode: press Ctrl+5.
On Build Settings tab under Build Steps click on Add Build Step.
Choose Make from the menu.
Write install into Make arguments: text input box.
(The version where I checked these is Qt Creator 2.4.1.)
I was using Shadow Build on Window 7 and I ran into the same problem than you.
Moreover, after setting my INSTALLS and running make install I was having the following message :
Nothing to be done for `install'.
The reason is that you have to set $$DESTDIR yourself.
In my case I wanted to copy *.qml files, that's how I achieved it:
# if you are using Shadow build, you need to get the output folder
CONFIG(release, debug|release): DESTDIR = $$OUT_PWD/release
CONFIG(debug, debug|release): DESTDIR = $$OUT_PWD/debug
# if you are using normal build (non-shadow) that would have worked as well.
CONFIG(release, debug|release): DESTDIR = release
CONFIG(debug, debug|release): DESTDIR = debug
QmlFiles.path = $$DESTDIR/Qml
QmlFiles.files += $$files(Qml/*.qml)
INSTALLS += QmlFiles
EDIT :
I figure out that $$OUT_PWD can be use to find the Shadow Build Output path. So, I fixed the code which finally come close to what you were using.
Well i have a folder called libqtlua-1.4 in which i have the libqtlua.so, the qtlua executable, and in libqtlua-1.4/src/QtLua i have the headers.
How can i include it in a qtcreator project?
(I am running in ubuntu 11.10)
Any suggestion would be appreciated.
You have to specify the library in you project file (file with .pro extension) to qmake be able to see them when compile:
LIBS += -L/path/to/your/lib/libqtlua-1.4 -lqtlua
INCLUDEPATH += /path/to/your/lib/libqtlua-1.4/src/QtLua
References: LIBS, INCLUDEPATH.