在 Qt 程序中,.pro 文件用于定义项目的配置和设置。当你的程序需要在 Windows 32 位和 64 位系统下编译时,你需要为每种架构配置适当的设置。下面是一个示例 .pro 文件,展示了如何在 Qt 项目中为 Windows 32 位和 64 位系统进行配置:
qmake
TEMPLATE = app
TARGET = MyApp
VERSION = 1.0.0
# 设置项目的源文件、头文件和资源文件
SOURCES += main.cpp \
mainwindow.cpp \
otherfile.cpp
HEADERS += mainwindow.h \
otherfile.h
RESOURCES += resources.qrc
# 针对 Windows 32 位系统的配置
win32 {
# 设置生成的可执行文件名和路径
CONFIG += windows console
# 设置生成的可执行文件名和路径
target.path = /path/to/output/32bit
# 设置生成的可执行文件名
target.name = MyApp-Win32
}
# 针对 Windows 64 位系统的配置
win64 {
CONFIG += windows console
# 设置生成的可执行文件名和路径
target.path = /path/to/output/64bit
# 设置生成的可执行文件名
target.name = MyApp-Win64
}
在这个示例中,.pro 文件定义了一个 Qt 应用程序项目。SOURCES、HEADERS 和 RESOURCES 行定义了项目的源文件、头文件和资源文件。然后,通过 win32 和 win64 部分,为 Windows 32 位和 64 位系统进行了配置。每个部分中,你可以设置生成的可执行文件的路径和名称,以及其他相关的配置选项。确保将 target.path 中的路径替换为你实际的目标输出路径。
再举一个较复杂的例子:
QT += core
TEMPLATE = lib
CONFIG += c++17
DESTDIR = ../QGIS
CONFIG(debug, debug|release){
MOC_DIR = ../build-QGIS/zip/Debug/moc
RCC_DIR = ../build-QGIS/zip/Debug/rcc
UI_DIR = ../build-QGIS/zip/Debug/ui
OBJECTS_DIR = ../build-QGIS/zip/Debug/obj
DESTDIR = ../build-QGIS/zip/Debug/obj
}else{
MOC_DIR = ../build-QGIS/zip/Release/moc
RCC_DIR = ../build-QGIS/zip/Release/rcc
UI_DIR = ../build-QGIS/zip/Release/ui
OBJECTS_DIR = ../build-QGIS/zip/Release/obj
DESTDIR = ../build-QGIS/zip/Release/obj
}
CONFIG(debug, debug|release){
TARGET = zipd
}else{
TARGET = zip
}
DEFINES -= UNICODE _UNICODE
win32: DEFINES += _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
#当前目录
INCLUDEPATH += ./ ./lib
#bz2 lzma zlib zstd
INCLUDEPATH += ../QGIS/include ../QGIS/include/lzma
#openssl路径
win32 {
INCLUDEPATH += D:/Qt/Tools/OpenSSL/Win_x64/include
INCLUDEPATH += D:/Qt/Tools/OpenSSL/Win_x64/include/openssl
}
linux* {
INCLUDEPATH += /opt/Qt/Tools/OpenSSL/src/include
INCLUDEPATH += /opt/Qt/Tools/OpenSSL/src/include/openssl
}
macx {
INCLUDEPATH += /usr/local/opt/openssl@3/include
INCLUDEPATH += /usr/local/opt/openssl@3/include/openssl
}
#LIBS
LIBS += -L../QGIS/lib
CONFIG(debug, debug|release){
LIBS += -lzlibd -lbz2d -llzmad -lzstdd
}else{
LIBS += -lzlib -lbz2 -llzma -lzstd
}
win32 {
LIBS += -LD:/Qt/Tools/OpenSSL/Win_x64/lib
LIBS += -llibcrypto
LIBS += -luser32 -lws2_32 -ladvapi32
}
linux* {
LIBS += -lcrypto
}
macx {
LIBS += -L/usr/local/opt/openssl@3/lib
LIBS += -lcrypto
}
#头文件
HEADERS += ./lib/zip.h
#源文件
SOURCES += ./lib/zip_add.c \
./lib/zip_add_dir.c \
./lib/zip_add_entry.c \
./lib/zip_algorithm_deflate.c \
./lib/zip_buffer.c \
./lib/zip_close.c \
./lib/zip_delete.c \
./lib/zip_dir_add.c \
./lib/zip_dirent.c \
./lib/zip_discard.c \
./lib/zip_entry.c \
./lib/zip_error.c \
./lib/zip_error_clear.c \
./lib/zip_error_get.c \
./lib/zip_error_get_sys_type.c \
./lib/zip_error_strerror.c \
./lib/zip_error_to_str.c \
./lib/zip_extra_field.c \
./lib/zip_extra_field_api.c \
./lib/zip_fclose.c \
./lib/zip_fdopen.c \
./lib/zip_file_add.c \
./lib/zip_file_error_clear.c \
./lib/zip_file_error_get.c \
./lib/zip_file_get_comment.c \
./lib/zip_file_get_external_attributes.c \
./lib/zip_file_get_offset.c \
./lib/zip_file_rename.c \
./lib/zip_file_replace.c \
./lib/zip_file_set_comment.c \
./lib/zip_file_set_encryption.c \
./lib/zip_file_set_external_attributes.c \
./lib/zip_file_set_mtime.c \
./lib/zip_file_strerror.c \
./lib/zip_fopen.c \
./lib/zip_fopen_encrypted.c \
./lib/zip_fopen_index.c \
./lib/zip_fopen_index_encrypted.c \
./lib/zip_fread.c \
./lib/zip_fseek.c \
./lib/zip_ftell.c \
./lib/zip_get_archive_comment.c \
./lib/zip_get_archive_flag.c \
./lib/zip_get_encryption_implementation.c \
./lib/zip_get_file_comment.c \
./lib/zip_get_name.c \
./lib/zip_get_num_entries.c \
./lib/zip_get_num_files.c \
./lib/zip_hash.c \
./lib/zip_io_util.c \
./lib/zip_libzip_version.c \
./lib/zip_memdup.c \
./lib/zip_name_locate.c \
./lib/zip_new.c \
./lib/zip_open.c \
./lib/zip_pkware.c \
./lib/zip_progress.c \
./lib/zip_rename.c \
./lib/zip_replace.c \
./lib/zip_set_archive_comment.c \
./lib/zip_set_archive_flag.c \
./lib/zip_set_default_password.c \
./lib/zip_set_file_comment.c \
./lib/zip_set_file_compression.c \
./lib/zip_set_name.c \
./lib/zip_source_accept_empty.c \
./lib/zip_source_begin_write.c \
./lib/zip_source_begin_write_cloning.c \
./lib/zip_source_buffer.c \
./lib/zip_source_call.c \
./lib/zip_source_close.c \
./lib/zip_source_commit_write.c \
./lib/zip_source_compress.c \
./lib/zip_source_crc.c \
./lib/zip_source_error.c \
./lib/zip_source_file_common.c \
./lib/zip_source_file_stdio.c \
./lib/zip_source_free.c \
./lib/zip_source_function.c \
./lib/zip_source_get_file_attributes.c \
./lib/zip_source_is_deleted.c \
./lib/zip_source_layered.c \
./lib/zip_source_open.c \
./lib/zip_source_pkware_decode.c \
./lib/zip_source_pkware_encode.c \
./lib/zip_source_read.c \
./lib/zip_source_remove.c \
./lib/zip_source_rollback_write.c \
./lib/zip_source_seek.c \
./lib/zip_source_seek_write.c \
./lib/zip_source_stat.c \
./lib/zip_source_supports.c \
./lib/zip_source_tell.c \
./lib/zip_source_tell_write.c \
./lib/zip_source_window.c \
./lib/zip_source_write.c \
./lib/zip_source_zip.c \
./lib/zip_source_zip_new.c \
./lib/zip_stat.c \
./lib/zip_stat_index.c \
./lib/zip_stat_init.c \
./lib/zip_strerror.c \
./lib/zip_string.c \
./lib/zip_unchange.c \
./lib/zip_unchange_all.c \
./lib/zip_unchange_archive.c \
./lib/zip_unchange_data.c \
./lib/zip_utf-8.c \
./lib/zip_err_str.c \
\
./lib/zip_algorithm_bzip2.c \
./lib/zip_algorithm_xz.c \
./lib/zip_algorithm_zstd.c \
./lib/zip_crypto_openssl.c \
./lib/zip_winzip_aes.c \
./lib/zip_source_winzip_aes_decode.c \
./lib/zip_source_winzip_aes_encode.c
win32 {
SOURCES += ./lib/zip_source_file_win32.c \
./lib/zip_source_file_win32_named.c \
./lib/zip_source_file_win32_utf16.c \
./lib/zip_source_file_win32_utf8.c \
./lib/zip_source_file_win32_ansi.c \
./lib/zip_random_win32.c
}
linux* {
SOURCES += ./lib/zip_source_file_stdio_named.c \
./lib/zip_random_unix.c
}
macx {
SOURCES += ./lib/zip_source_file_stdio_named.c \
./lib/zip_random_unix.c
}
QMAKE_PRE_LINK += \
mkdir -p $${PWD}/../QGIS/bin \
mkdir -p $${PWD}/../QGIS/lib \
mkdir -p $${PWD}/../QGIS/include \
win32 {
QMAKE_POST_LINK += cp $${DESTDIR}/*.dll $${PWD}/../QGIS/bin/ && \
cp $${DESTDIR}/*.lib $${PWD}/../QGIS/lib/ && \
cp $${DESTDIR}/*.exp $${PWD}/../QGIS/bin/
CONFIG(debug, debug|release){
QMAKE_POST_LINK += && \
cp $${DESTDIR}/*.pdb $${PWD}/../QGIS/bin/ && \
cp $${DESTDIR}/*.ilk $${PWD}/../QGIS/bin/
}
}
linux* {
QMAKE_POST_LINK += cp $${DESTDIR}/*.so $${PWD}/../QGIS/lib/
}
macx {
QMAKE_POST_LINK += cp $${DESTDIR}/*.dylib $${PWD}/../QGIS/lib/
}
QMAKE_POST_LINK += && \
cp $${PWD}/zipconf.h $${PWD}/../QGIS/include/
# Default rules for deployment.
#unix {
# target.path = /usr/lib
#}
#!isEmpty(target.path): INSTALLS += target