c++ - 无法使用构建后命令将 .dll 移动到可执行文件
问题描述
所以我对大型项目的工作相当陌生。我正在尝试使用 premake5 为 Visual Studio 2019 生成项目和解决方案
这就是我的预制 lua 文件中的内容
workspace "DragonHeart"
architecture "x64"
startproject "Sandbox"
configurations
{
"Debug",
"Release",
"Dist"
}
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
project "DragonHeart"
location "DragonHeart"
kind "SharedLib"
language "C++"
targetdir ("bin" .. outputdir .. "/%{prj.name}")
objdir ("bin-int" .. outputdir .. "/%{prj.name}")
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp"
}
includedirs
{
"%{prj.name}/vendor/spdlog/include"
}
filter "system:windows"
cppdialect "C++14"
staticruntime "On"
systemversion "latest"
defines
{
"DH_PLATFORM_WINDOWS",
"DH_BUILD_DLL"
}
postbuildcommands
{
{"{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/Sandbox"}
}
filter "configurations:Debug"
defines "DH_DEBUG"
symbols "On"
filter "configurations:Release"
defines "DH_RELEASE"
optimize "On"
filter "configurations:Dist"
defines "DH_DIST"
optimize "On"
project "Sandbox"
location "Sandbox"
kind "ConsoleApp"
language "C++"
targetdir ("bin" .. outputdir .. "/%{prj.name}")
objdir ("bin-int" .. outputdir .. "/%{prj.name}")
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp"
}
includedirs
{
"DragonHeart/vendor/spdlog/include",
"DragonHeart/src"
}
links
{
"DragonHeart"
}
filter "system:windows"
cppdialect "C++14"
staticruntime "On"
systemversion "latest"
defines
{
"DH_PLATFORM_WINDOWS"
}
filter "configurations:Debug"
defines "DH_DEBUG"
symbols "On"
filter "configurations:Release"
defines "DH_RELEASE"
optimize "On"
filter "configurations:Dist"
defines "DH_DIST"
optimize "On"
我的问题是当我运行并尝试构建东西时,VS2019 遇到了后期构建的问题。
Severity Code Description Project File Line Suppression State
Error MSB3073 The command "IF EXIST ..\binDebug-windows-x86_64\DragonHeart\DragonHeart.dll\ (xcopy /Q /E /Y /I ..\binDebug-windows-x86_64\DragonHeart\DragonHeart.dll ..\bin\Debug-windows-x86_64\Sandbox > nul) ELSE (xcopy /Q /Y /I ..\binDebug-windows-x86_64\DragonHeart\DragonHeart.dll ..\bin\Debug-windows-x86_64\Sandbox > nul)
:VCEnd" exited with code 2. DragonHeart C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets 155
我不确定为什么它不起作用。我知道 .dll 之后有一个 \ 但手动删除它不会改变任何东西。而且我认为退出代码2意味着它找不到文件,但是将文件路径与实际存在的路径进行比较,它看起来应该找到它。我不知道如何解决这个问题,任何帮助将不胜感激。
解决方案
我遇到了和你一样的问题,我通过将 postbuildcommands 放在 Sandbox 项目中并更改复制指令的目录来解决它。您应该在 Sandbox 项目的 windows 过滤器中添加它,并从 DragonHeart 项目中删除 postbuildcommands
postbuildcommands
{
"{COPY} ../bin/" .. outputdir .. "/DragonHeart/*.dll ../bin/" .. outputdir .. "/Sandbox"
}
我不知道为什么其他代码不起作用,但这似乎绕过了问题
推荐阅读
- javascript - Join two arrays in to one - Javascript
- ios - crash_info_entry_0:CoreUI:释放 _CUIInternalLinkRendition ... Assets.car
- c# - 使用数组查询 cosmos 数据库以过滤文档
- colors - 在一组函数上应用调色板颜色
- php - 当表格为空时插入表格?
- flutter - 如何在 hive 对象中编写自定义类对象?
- python - 使用 ezdxf 界面从 Python 导出网格后无法在 Freecad 中显示网格
- python - 如何安装 \lib\runpy.py
- ionic-framework - 最后一列跳转到离子网格 Ionic 4 中的下一行
- elasticsearch - Kibana 服务器未就绪