一 QT 上的 .pro 文件 将 linux,mac和windows上配置设置为可以共享
1. 先来看文件夹布局
2. 再来看 QT 中的 .pro文件
.pro 文件的写法
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
# 添加windows的配置,这里不管你是win32 还是 win64 ,都是统一使用 win32
win32 {
FFMPEG_HOME = ../ffmpeg-6.0-full_build-shared
SDL_HOME = ../SDL2-devel-2.0.14-mingw/SDL2-2.0.14/x86_64-w64-mingw32
#INCLUDEPATH += 的意思是再原先的INCLUDEPATH的基础上,再添加等号后面的值 $${SDL_HOME}的意思是从 SDL_HOME中取出值,也就是 ../sdl,
#连起来看,这句话的意思是,给原先的 INCLUDEPATH ,再加上 当前.pro文件的上一级目录下的/sdl/include
#INCLUDEPATH 的意思是添加 .h文件
INCLUDEPATH += $${SDL_HOME}/include/SDL2 \
$${FFMPEG_HOME}/include
#LIBS 的意思是添加静态库和动态库的访问路径,
LIBS += -L$${SDL_HOME}/lib \
-L$${FFMPEG_HOME}/lib \
-lavcodec \
-lavdevice \
-lavfilter \
-lavformat \
-lavutil \
-lpostproc \
-lswscale \
-lswresample \
-lsdl2
# message()可以用来打印
message(11111111111)
message($${SDL_HOME})
message($${FFMPEG_HOME})
message($$(PATH))
}
mac {
FFMPEG_HOME = /usr/local/Cellar/ffmpeg/4.3.2
SDL_HOME = /usr/local/Cellar/SDL2-devel-2.0.14-mingw/SDL2-2.0.14/
INCLUDEPATH += $${SDL_HOME}/include/SDL2 \
$${FFMPEG_HOME}/include
#LIBS 的意思是添加静态库和动态库的访问路径,
LIBS += -L$${SDL_HOME}/lib \
-L$${FFMPEG_HOME}/lib \
-lavcodec \
-lavdevice \
-lavfilter \
-lavformat \
-lavutil \
-lpostproc \
-lswscale \
-lswresample \
-lsdl2
}
# 库文件路径
#mac:INCLUDEPATH += $${FFMPEG_HOME}/include
# 需要链接哪些库?默认是链接动态库
#mac:LIBS += -L $${FFMPEG_HOME}/lib \
message()方法可以在.pro文件中 打印相关信息
# message()可以用来打印
message(11111111111)
message($${SDL_HOME})
message($${FFMPEG_HOME})
message($$(PATH))
可以看到message 打印相关的信息 是在 QT 的 "概要信息" 中的。
我们将信息分析如下:
Project MESSAGE: 11111111111
Project MESSAGE: ../SDL2-devel-2.0.14-mingw/SDL2-2.0.14/x86_64-w64-mingw32
Project MESSAGE: ../ffmpeg-6.0-full_build-shared
/// PATH 信息,前三行为QT 安装的path,下来是 系统变量, 最后三行是Anminister的用户变量
Project MESSAGE: C:\Qt\Qt5.14.2\Tools\mingw730_64\bin;
C:\Qt\Qt5.14.2\5.14.2\mingw73_64\bin;
C:\Qt\Qt5.14.2\Tools\mingw730_64\bin;
D:\Ctool\ffmpeg-4.2.1-win32-shared\bin;
C:\Program Files (x86)\VMware\VMware Workstation\bin\;
D:\Ctool\yinshipin\ffmpeg-6.0-full_build-shared\bin;
C:\Program Files\Microsoft MPI\Bin\;
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\windows\system32;
C:\windows;
C:\windows\System32\Wbem;
C:\windows\System32\WindowsPowerShell\v1.0\;
C:\windows\System32\OpenSSH\;
C:\Program Files\dotnet\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\Program Files\IDM Computer Solutions\UltraEdit;
C:\Program Files\Git\cmd;
C:\Program Files\TortoiseGit\bin;
D:\Ctool\SDL2-devel-2.0.14-mingw\SDL2-2.0.14\x86_64-w64-mingw32\bin;
D:\Ctool\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\bin;
C:\Program Files\CMake\bin;
D:\Ctool\protobuf\protobuf-windows\bin;
D:\Ctool\protobuf\protobuf-windows\lib;
C:\Program Files\Java\jdk1.8.0_241\bin;
C:\Program Files\Microsoft VS Code\bin;
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64;
D:\Ctool\SDL2-devel-2.0.14-mingw\SDL2-2.0.14\x86_64-w64-mingw32\bin;
C:\Program Files\OpenSSL-Win64\bin;
C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;
C:\Users\Administrator\.dotnet\tools;
C:\Program Files\JetBrains\CLion 2023.3.4\bin;
3.注意的问题
我们在这里 加载了 ffmpeg 库,加载了sdl的库,要注意的是:在加载多个第三方库的时候,INCLUDEPATH,LIBS时,只能写一个,不能写多个,否则build fail。
INCLUDEPATH += $${SDL_HOME}/include/SDL2 \
$${FFMPEG_HOME}/include
#LIBS 的意思是添加静态库和动态库的访问路径,
LIBS += -L$${SDL_HOME}/lib \
-L$${FFMPEG_HOME}/lib \
-lavcodec \
-lavdevice \
-lavfilter \
-lavformat \
-lavutil \
-lpostproc \
-lswscale \
-lswresample \
-lsdl2