Jak określić różne katalogi wyjściowe Debug/Release w QMake.pro plik
Mam projekt Qt i chciałbym wypisywać pliki kompilacji poza drzewem źródłowym.
Obecnie mam następującą strukturę katalogów:
/
|_/build
|_/mylib
|_/include
|_/src
|_/resources
W zależności od konfiguracji (debug/release), chcę wypisać pliki wynikowe z katalogu build w katalogu build / debug lub build/release.
Jak mogę to zrobić używając pliku. pro?
11 answers
Krótka odpowiedź brzmi: ty nie .
Powinieneś uruchomić qmake
, a następnie make
w dowolnym katalogu, w którym chcesz zbudować. Uruchom go raz w katalogu debug
, raz w katalogu release
.
Tak każdy budujący Twój projekt oczekiwałby, że będzie działał, i tak samo QT jest skonfigurowane do budowania, tak również Qt Creator oczekuje zachowania Twojego pliku .pro
: po prostu uruchamia się qmake
, a następnie make
w folderze budowania dla wybranego celu konfiguracja.
Jeśli chcesz utworzyć te foldery i wykonać w nich dwie (lub więcej) Kompilacje, potrzebujesz pliku makefile najwyższego poziomu, prawdopodobnie utworzonego z pliku projektu najwyższego poziomu za pomocą qmake.
Często zdarza się mieć więcej niż dwie konfiguracje kompilacji, więc niepotrzebnie zobowiązujesz się do rozróżniania tylko kompilacji od wydania; możesz mieć Kompilacje z różnymi poziomami optymalizacji itp. dychotomia debug/release najlepiej pozostawić na spoczynek w pokój.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-04-07 20:34:05
Dla mojego projektu Qt, używam tego schematu w pliku*. pro:
HEADERS += src/dialogs.h
SOURCES += src/main.cpp \
src/dialogs.cpp
Release:DESTDIR = release
Release:OBJECTS_DIR = release/.obj
Release:MOC_DIR = release/.moc
Release:RCC_DIR = release/.rcc
Release:UI_DIR = release/.ui
Debug:DESTDIR = debug
Debug:OBJECTS_DIR = debug/.obj
Debug:MOC_DIR = debug/.moc
Debug:RCC_DIR = debug/.rcc
Debug:UI_DIR = debug/.ui
To proste, ale miłe! :)Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-04-06 08:34:59
Aby zmienić katalog docelowy dll / exe, użyj tego w pliku pro:
CONFIG(debug, debug|release) {
DESTDIR = build/debug
} else {
DESTDIR = build/release
}
Możesz również zmienić Katalogi dla innych obiektów docelowych, takich jak pliki obiektowe i pliki moc (sprawdź qmake variable reference dla szczegółów lub qmake Config() function reference ).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-20 18:13:53
Mam bardziej zwarte podejście:
release: DESTDIR = build/release
debug: DESTDIR = build/debug
OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.ui
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-13 11:17:22
Poprawny sposób na to jest następujący (dzięki Qt Support Team):
CONFIG(debug, debug|release) {
DESTDIR = build/debug
}
CONFIG(release, debug|release) {
DESTDIR = build/release
}
OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.u
Więcej informacji tutaj: https://wiki.qt.io/Qt_project_org_faq#What_does_the_syntax_CONFIG.28debug.2Cdebug.7Crelease.29_mean_.3F_What_does_the_1st_argument_specify_and_similarly_what_is_the_2nd_.3F
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-10 11:53:30
Używam tej samej metody sugerowanej przez Chalupa,
ParentDirectory = <your directory>
RCC_DIR = "$$ParentDirectory\Build\RCCFiles"
UI_DIR = "$$ParentDirectory\Build\UICFiles"
MOC_DIR = "$$ParentDirectory\Build\MOCFiles"
OBJECTS_DIR = "$$ParentDirectory\Build\ObjFiles"
CONFIG(debug, debug|release) {
DESTDIR = "$$ParentDirectory\debug"
}
CONFIG(release, debug|release) {
DESTDIR = "$$ParentDirectory\release"
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-06-16 21:05:00
Stare pytanie, ale wciąż warte aktualnej odpowiedzi. Obecnie często robi się to samo, co Qt Creator, gdy używane są Shadow buildy (są one domyślnie włączone podczas otwierania nowego projektu).
Dla każdego innego celu i typu kompilacji, prawy {[3] } jest uruchamiany z odpowiednimi argumentami w innym katalogu kompilacji. To jest po prostu zbudowany z prostych make
.
Więc wyimaginowana struktura katalogów może wyglądać tak.
/
|_/build-mylib-qt5-mingw32-debug
|_/build-mylib-qt5-mingw32-release
|_/build-mylib-qt4-msvc2010-debug
|_/build-mylib-qt4-msvc2010-release
|_/build-mylib-qt5-arm-debug
|_/build-mylib-qt5-arm-release
|_/mylib
|_/include
|_/src
|_/resources
A improtant jest taki, że qmake
jest prowadzony w katalog budowy:
cd build-mylib-XXXX
/path/to/right/qmake ../mylib/mylib.pro CONFIG+=buildtype ...
Następnie generuje pliki Makefile w katalogu build, a następnie make
generuje również pliki pod nim. Nie ma ryzyka, że różne wersje zostaną pomieszane, o ile qmake nigdy nie zostanie uruchomiony w katalogu źródłowym (jeśli tak jest, lepiej dobrze to Wyczyść!).
A gdy zrobi się to w ten sposób, plik .pro
z aktualnie akceptowanej odpowiedzi jest jeszcze prostszy:
HEADERS += src/dialogs.h
SOURCES += src/main.cpp \
src/dialogs.cpp
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-05 19:04:09
Przydatne jest również posiadanie nieco innej nazwy dla pliku wykonywalnego. Nie można użyć czegoś takiego jak:
release: Target = ProgramName
debug: Target = ProgramName_d
Dlaczego to nie działa, nie jest jasne, ale tak nie jest. Ale:
CONFIG(debug, debug|release) {
TARGET = ProgramName
} else {
TARGET = ProgramName_d
}
To działa tak długo, jak linia CONFIG +=
ją poprzedza.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-29 19:20:32
Nowa wersja Qt Creator posiada również opcję budowania "profile"pomiędzy debugowaniem a wydaniem. Oto jak to wykrywam:
CONFIG(debug, debug|release) { DEFINES += DEBUG_MODE }
else:CONFIG(force_debug_info) { DEFINES += PROFILE_MODE }
else { DEFINES += RELEASE_MODE }
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-20 18:22:32
1. Find Debug / Release in CONFIG
Pobranie bieżącego (debugowania | wydania).
specified_configs=$$find(CONFIG, "\b(debug|release)\b")
build_subdir=$$last(specified_configs)
(może być wiele, więc zachowaj tylko ostatnie podane w kompilacji):
2. Set DESTDIR
Użyj ma nazwę build subdir
DESTDIR = $$PWD/build/$$build_subdir
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-03-06 06:39:49
To jest mój plik Makefile dla różnych katalogów wyjściowych debugowania/wydania. Ten Makefile został pomyślnie przetestowany na Ubuntu linux. Powinno działać bezproblemowo na Windows pod warunkiem, że Mingw-w64 jest zainstalowany poprawnie.
ifeq ($(OS),Windows_NT)
ObjExt=obj
mkdir_CMD=mkdir
rm_CMD=rmdir /S /Q
else
ObjExt=o
mkdir_CMD=mkdir -p
rm_CMD=rm -rf
endif
CC =gcc
CFLAGS =-Wall -ansi
LD =gcc
OutRootDir=.
DebugDir =Debug
ReleaseDir=Release
INSTDIR =./bin
INCLUDE =.
SrcFiles=$(wildcard *.c)
EXEC_main=myapp
OBJ_C_Debug =$(patsubst %.c, $(OutRootDir)/$(DebugDir)/%.$(ObjExt),$(SrcFiles))
OBJ_C_Release =$(patsubst %.c, $(OutRootDir)/$(ReleaseDir)/%.$(ObjExt),$(SrcFiles))
.PHONY: Release Debug cleanDebug cleanRelease clean
# Target specific variables
release: CFLAGS += -O -DNDEBUG
debug: CFLAGS += -g
################################################
#Callable Targets
release: $(OutRootDir)/$(ReleaseDir)/$(EXEC_main)
debug: $(OutRootDir)/$(DebugDir)/$(EXEC_main)
cleanDebug:
-$(rm_CMD) "$(OutRootDir)/$(DebugDir)"
@echo cleanDebug done
cleanRelease:
-$(rm_CMD) "$(OutRootDir)/$(ReleaseDir)"
@echo cleanRelease done
clean: cleanDebug cleanRelease
################################################
# Pattern Rules
# Multiple targets cannot be used with pattern rules [https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html]
$(OutRootDir)/$(ReleaseDir)/%.$(ObjExt): %.c | $(OutRootDir)/$(ReleaseDir)
$(CC) -I$(INCLUDE) $(CFLAGS) -c $< -o"$@"
$(OutRootDir)/$(DebugDir)/%.$(ObjExt): %.c | $(OutRootDir)/$(DebugDir)
$(CC) -I$(INCLUDE) $(CFLAGS) -c $< -o"$@"
# Create output directory
$(OutRootDir)/$(ReleaseDir) $(OutRootDir)/$(DebugDir) $(INSTDIR):
-$(mkdir_CMD) $@
# Create the executable
# Multiple targets [https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html]
$(OutRootDir)/$(ReleaseDir)/$(EXEC_main): $(OBJ_C_Release)
$(OutRootDir)/$(DebugDir)/$(EXEC_main): $(OBJ_C_Debug)
$(OutRootDir)/$(ReleaseDir)/$(EXEC_main) $(OutRootDir)/$(DebugDir)/$(EXEC_main):
$(LD) $^ -o$@
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-06-12 18:13:55