# If operating system is Windows perform this V
win32 {
# Create variable containing the path to your project compile folder ( probably no need to change since this is automated by Qt )
OUT_PWD_WINDOWS = $$OUT_PWD
# Switch frontslashes with double backslashes
OUT_PWD_WINDOWS ~= s,/,\\,g
# Create variables to set debug path and release path
# Gotta change the \\debug and \\release to the correct debug and release folders
OUT_PWD_WINDOWS_DEBUG = $$quote( $$OUT_PWD_WINDOWS\\debug )
OUT_PWD_WINDOWS_RELEASE = $$quote( $$OUT_PWD_WINDOWS\\release )
# Create variables to set the path to libs and dlls you want to copy ( *.lib will copy all files ending in .lib from the specified path )
# you can change that however to mysql.lib for example if you only want 1, same goes for .dll
LIBS_TO_COPY = $$quote( C:\\MySql\\libs\\*.lib )
DLLS_TO_COPY = $$quote( C:\\MySql\\libs\\*.dll )
# Copy libraries and dlls into debug path / else copys them into the release folder
# essentially this is saying if( config == debug ) perform tasks else perform tasks for release, which is add actions to be executed after linking
CONFIG( debug , debug|release ) {
# Here we add the copy command to the QMAKE_POST_LINK variable which will be executed once the linking is done
# We have 1 entry for libs and 1 for dlls, same goes for the release which is in the else
QMAKE_POST_LINK += $$quote( xcopy $$LIBS_TO_COPY $$OUT_PWD_WINDOWS_DEBUG $$escape_expand( \n\t ) )
QMAKE_POST_LINK += $$quote( xcopy $$DLLS_TO_COPY $$OUT_PWD_WINDOWS_DEBUG $$escape_expand( \n\t ) )
} else {
QMAKE_POST_LINK += $$quote( xcopy $$LIBS_TO_COPY $$OUT_PWD_WINDOWS_RELEASE $$escape_expand( \n\t ) )
QMAKE_POST_LINK += $$quote( xcopy $$DLLS_TO_COPY $$OUT_PWD_WINDOWS_RELEASE $$escape_expand( \n\t ) )
}
}
2条答案
按热度按时间drkbr07n1#
你能做的不多--windows搜索
.dll
对于来自不同地方的共享库来说,所有这些都是可怕的(想想如果多个应用程序想要安装它们自己的副本/版本会发生什么):引用自https://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.140).aspx:
通过隐式和显式链接,windows首先搜索“已知dll”,如kernel32.dll和user32.dll。然后,windows按以下顺序搜索DLL:
当前进程的可执行模块所在的目录。
当前目录。
windows系统目录。getsystemdirectory函数检索此目录的路径。
windows目录。getwindowsdirectory函数检索此目录的路径。
path环境变量中列出的目录。
你在做1,这是唯一明智的做法。
在系统的用户上,也可以使用5。和修改路径(但如果您想创建可部署的包,这是行不通的!)。
2., 3. 和4。对应用程序开发人员来说是完全无用的。
qnakjoqk2#
您有几个选项可以自动执行此过程:
一种方法是将库路径添加到
main.cpp
.或者让整个过程自动化:
来自qt文档:
qmake\u post\u链接
指定将目标链接在一起后要执行的命令。此变量通常为空,因此不执行任何操作。
现在重命名/删除你的构建文件夹,把它放到你的
.pro
文件,进行路径调整,您可以将其粘贴到所有.pro
将这些库提供给需要它们的地方。您甚至可以通过创建一个宏/keybind/snippet将其加载到
.pro
文件夹。旁注:对于其他操作系统,您必须使用特定于操作系统的命令来编写
编译器输出: