Using Qt 5.12. I have been trying to make some QMake commands to run only once (instead of three times). I found this answer, where they make use of the !build_pass condition. So I set up my working directory as follows:
│ subdirs_test.pro
│
└───test
test.pro
The test/test.pro file only contains:
!build_pass:message("This message should appear only once")
And the subdirs_test.pro contains:
TEMPLATE = subdirs
SUBDIRS = \
test
test.subdir = $$PWD/test
If I run:
cd test
qmake -tp vc test.pro
Well enough it prints:
Project MESSAGE: This message should appear only once
But if I run the subdirs project:
cd ..
qmake -r -tp vc subsdirs_test.pro
It prints the message twice:
Project MESSAGE: This message should appear only once
Project MESSAGE: This message should appear only once
Is there a way to make QMake just run it once?
defineReplace(commonFunctionality) {
message("commonFunctionality")
}
build_pass {
CONFIG(debug, debug|release) {
message("Debug")
$$commonFunctionality();
}
CONFIG(release, debug|release) {
message("Release")
$$commonFunctionality();
}
}
$ qmake -r -tp vc subdirs_test.pro
Project MESSAGE: Release
Project MESSAGE: commonFunctionality
Project MESSAGE: Debug
Project MESSAGE: commonFunctionality
$ qmake -r -tp vc test.pro
Project MESSAGE: Release
Project MESSAGE: commonFunctionality
Project MESSAGE: Debug
Project MESSAGE: commonFunctionality
Related
I have a Qt library project and I want to install some files in a specific folder.
The "MyLib.pro" project file is:
...
win32 {
CONFIG(release, debug|release) {
libFiles.files = $$OUT_PWD/release/MyLib.lib
libFiles.path = $$PWD/../staticlib/release
}
CONFIG(debug, debug|release) {
libFiles.files = $$OUT_PWD/debug/MyLib.lib
libFiles.files += $$OUT_PWD/debug/MyLib.pdb
libFiles.path = $$PWD/../staticlib/debug
}
headerFiles.files = $$PWD/MyLib.h
headerFiles.path = $$PWD/../staticlib/include
}
!isEmpty(libFiles.path) {
INSTALLS += libFiles
}
!isEmpty(headerFiles.path) {
INSTALLS += headerFiles
}
Using QtCreator and adding a new build step "make install" all works fine and the library built is installed into the specified path given the specified build.
If I want to do the same using the command line like below
cd %PATH_TO_LIB_SRC%
cd ..
mkdir build
cd build
qmake "CONFIG+=debug_and_release" ../src/MyLib.pro
nmake -f Makefile.Debug
nmake -f MakeFile.Debug install
the install command copy only the header file. If I re-run the qmake and the nmake command, repeating the nmake install command now copies also the library files.
Concluding, the only solution that I found is to repeat the commands like below:
...
qmake "CONFIG+=debug_and_release" ../src/MyLib.pro
nmake -f Makefile.Debug
nmake -f Makefile.Release
qmake "CONFIG+=debug_and_release" ../src/MyLib.pro
nmake -f Makefile.Debug
nmake -f Makefile.Release
nmake -f MakeFile.Debug install
nmake -f MakeFile.Release install
What I'm wronging? I'm missing something like QMAKE_EXTRA_TARGETS or POST_TARGETDEPS?
UPDATE:
I compared the "Makefile", "Makefile.Debug" "Makefile.Release" of the first and the second run and:
"Makefile" are the same
for "Makefile.Debug" and "Makefile.Release", the new ones have only the install instruction for the .lib and .pcb files. I report the difference below.
...
+ ####### Install
+ install_libFiles: first FORCE
+ #if not exist C:$(INSTALL_ROOT)\libs\MyLib\build\..\staticlib\debug mkdir C:$(INSTALL_ROOT)\libs\MyLib\build\..\staticlib\debug & if not exist C:$(INSTALL_ROOT)\libs\MyLib\build\..\staticlib\debug exit 1
+ $(QINSTALL) C:\libs\MyLib\build\debug\MyLib.lib ...
...
+ uninstall_libFiles: FORCE
+ -$(DEL_FILE) C:$(INSTALL_ROOT)\libs\MyLib\build\..\staticlib\debug\MyLib.pdb
...
install: +install_libFiles+ install_headerFiles FORCE
uninstall: +uninstall_libFiles+ uninstall_headerFiles FORCE
OS: Windows 10, x64
I have a simple demo of qt console project, which simply print hello world.
This project can be built and run correctly(with MSVC kit), but I want to separate the process.
First, I click "execute qmake" in the right-click menu on the project in Qt Creator, I got a make file in the release and debug directory
build-hello-Desktop_Qt_5_12_3_MSVC2017_64bit-Release\makefile
open cmd, cd to this directory, and then the story ends.
If I use nmake, I got error C1083, which tell me can not find stdio.h
If I use make on windows or mingw-make32, I still got an error missing separator.
I have 2 questions:
1.Can someone give a full instruction of how to make this makefile both with mingw-make32 and nmake?
2.The makefile generated by qmake looks very complex and illegible, not like those makefiles in tutorial. Is it just the same as a normal makefile, or it's special?
I search for a lot but still can get the clear solution so please help.
the Makefile looks like this:
#############################################################################
# Makefile for building: hello
# Generated by qmake (3.1) (Qt 5.12.3)
# Project: ..\name\hello.pro
# Template: app
# Command: C:\Qt\Qt5.12.3\5.12.3\msvc2017_64\bin\qmake.exe -o Makefile ..\name\hello.pro -spec win32-msvc "CONFIG+=qtquickcompiler"
#############################################################################
MAKEFILE = Makefile
EQ = =
first: release
install: release-install
uninstall: release-uninstall
QMAKE = C:\Qt\Qt5.12.3\5.12.3\msvc2017_64\bin\qmake.exe
DEL_FILE = del
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
COPY = copy /y
COPY_FILE = copy /y
COPY_DIR = xcopy /s /q /y /i
INSTALL_FILE = copy /y
INSTALL_PROGRAM = copy /y
INSTALL_DIR = xcopy /s /q /y /i
QINSTALL = C:\Qt\Qt5.12.3\5.12.3\msvc2017_64\bin\qmake.exe -install qinstall
QINSTALL_PROGRAM = C:\Qt\Qt5.12.3\5.12.3\msvc2017_64\bin\qmake.exe -install qinstall -exe
DEL_FILE = del
SYMLINK = $(QMAKE) -install ln -f -s
DEL_DIR = rmdir
MOVE = move
SUBTARGETS = \
release \
debug
full instruction of how to make this makefile with nmake
run visual studio command prompt and then run nmake inside it rather than run nmake in common cmd, because vs command prompt has already set the specific environment variables such as the path of includes and c++ standard library, whichout which cl.exe and link.exe can not work.
This is the reason exacly why can not find stdio.h.
When I try to generate a makefile with qmake in a sub-directory, the makefile is generated in a wrong directory.
Here is my QmakeTest.pro, the main.cpp is a simple hello world code :
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
When I run qmake:
qmake -makefile -o build/makefile
qmake -makefile -o build/makefile
The first time, the folder build/ is created and the makefile is created in the right directory, the second time(and each time if build/ already exist), the makefile is generated in the folder build/build/ (a subfolder build inside the first one).
Why does qmake create a second subdirectory if the subdirectory build/ already exist ?
For info: qmake --version
QMake version 3.0
Using Qt version 5.3.0 in /usr/lib/x86_64-linux-gnu
Edit: The bug seems to be fixed with the QMake provided with qt 5.4.0
You can use
QMAKE_MAKEFILE += build/makefile
in your project file to create the makefile
so i m trying to setup a movable folder for a Qt project where I 'll have this structure and everything will be dependent ONLY with that content..
project\
script.dat "script to invoke qmake with just a click"
qmake.exe
moc.exe
mkspec\ "win32-msvc2010" copy
common\ "necessary by qmake" copy
project.pro
sources\
main.cpp
etc...
headers\
etc...
depedencies\
Qt\
include\
lib\
dll\
e.g.Boost\
include\
lib\
dll\
as can be seen i want a decent folder structure where the script will append the path to the dlls and set QMAKESPEC etc with respect to the %cd% (PWD) directory of the .pro file...
However the problem arises when i invoke qmake.exe
C:\Users\ardit\Desktop\test>qmake -v
QMake version 3.0
Using Qt version 5.2.1 in C:\build-essential\Qt\5.2.1\msvc2010_opengl\lib
and after that
qmake -tp vc
creates a project that has everything linked to my Qt installation and NOT the folder specified in the pro
visual studio additional include directories:
"include";".";"........\build-essential\Qt\5.2.1\msvc2010_opengl\include";"........\build-essential\Qt\5.2.1\msvc2010_opengl\include\QtGui";"........\build-essential\Qt\5.2.1\msvc2010_opengl\include\QtCore";"debug";........\build-essential\Qt\5.2.1\msvc2010_opengl\mkspecs\win32-msvc2010;%(AdditionalIncludeDirectories)
I havent put the Qt installation in the Path, but still the qmake.exe knows it somewhow (registry perhaps?)...
example .pro file where include\ has copy of Qt5\include\ , lib\ and dll\ as well
TARGET= test
SOURCES += main.cpp\
mainwindow.cpp \
glwindow.cpp
HEADERS += mainwindow.h \
glwindow.h
INCLUDEPATH=$${PWD}\include $$PWD
DEPENDPATH=$${PWD}\include $$PWD
LIBPATH=$${PWD}\lib
LIBS+=-L$$LIBPATH -lQt5Core -lQt5Gui -lQt5Widgets
Sidenote: I m new here so plz dont bash me...
any help appreciated...
I have no problem linking the dynamic opencv libraries, but I want to use static libraries instead, so I rebuilt OpenCV 2.3 with the "build shared libraries" option unchecked. I put the following on my .pro file
LIBS += "C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_calib3d231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_contrib231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_core231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_features2d231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_flann231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_gpu231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_imgproc231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_legacy231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_ml231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_objdetect231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_ts231.a" \
"C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_video231.a"
INCLUDEPATH += "C:\Program Files\openCV_static\opencv\build\install\include"
INCLUDEPATH += "C:\Program Files\openCV_static\opencv\build\install\include\opencv"
This is very similar to what I had before when I was using the dynamic libraries, except the .a files actually ended in .dll .a, and I put the dll's (not the dll.a files) in the qt program's output directory (so the program could find them and run). Now the whole point is that I don't need those dlls, so they're no longer in my program's output directory (actually they didn't build with OpenCV). But I get these errors when I try to build my program:
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN17CvVideoWriter_VFW5closeEv+0x13): undefined reference to `AVIStreamRelease#4'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN17CvVideoWriter_VFW5closeEv+0x25): undefined reference to `AVIStreamRelease#4'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN17CvVideoWriter_VFW5closeEv+0x37): undefined reference to `AVIFileRelease#4'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN16CvCaptureCAM_VFW4openEi+0x6c): undefined reference to `capGetDriverDescriptionA#20'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN16CvCaptureCAM_VFW4openEi+0xb7): undefined reference to `capCreateCaptureWindowA#32'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(cap_vfw.obj):cap_vfw.cpp:(.text$_ZN16CvCaptureAVI_VFW9grabFrameEv+0x29): undefined reference to `AVIStreamGetFrame#8'
.
.
.
.
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(grfmt_jpeg2000.obj):grfmt_jpeg2000.cpp:(.text$_ZN2cv13Jpeg2KEncoder5writeERKNS_3MatERKSt6vectorIiSaIiEE+0x17b): undefined reference to `jas_stream_close'
C:\Program Files\openCV_static\opencv\build\install\lib\libopencv_highgui231.a(grfmt_jpeg2000.obj):grfmt_jpeg2000.cpp:(.text.startup._GLOBAL__sub_I_C__Program_Files_openCV_static_opencv_modules_highgui_src_grfmt_jpeg2000.cpp+0x4): undefined reference to `jas_init'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [release\trusion.exe] Error 1
mingw32-make.exe: *** [release] Error 2
23:21:10: The process "C:\MinGW\bin\mingw32-make.exe" exited with code 2.
Error while building project trusion (target: Desktop)
When executing build step 'Make'
I am using MinGW. Compiling the project with the same toolchain used to build opencv. Worked with dynamic libs, as mentioned above. Does not work with static libs.
It seems you're missing Jasper dependency.
OpenCV on Windows uses pre-built libjasper library (lib/libjasper*), try adding them to LIBS
For the 'undefined reference to AVIStreamRelease#4'error, try linking against vfw32.lib or MSVFW32.dll