[英]DirectX12 with Premake5: Linking Directx12 Static Libraries
I'm switching to using a premake5 instead of just directly working with Visual Studio 2017. 我改用premake5,而不是直接使用Visual Studio 2017。
Here is how I linked against Dx12 in the past. 这是我过去与Dx12链接的方式。 I would put these macros in my main.cpp and it worked great.
我将这些宏放在main.cpp中,效果很好。
#pragma comment(lib, "d3d12.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3dcompiler.lib")
However, I was advised to not have including libraries in my source code. 但是,建议我不要在源代码中包含库。 And as I'm converting my project to premake5 I would like to know the proper way to handle this situation.
在将项目转换为premake5时,我想知道处理这种情况的正确方法。
Apologies I am new to tools like premake5. 抱歉,我是premake5之类的工具的新手。 And am unsure how to proceed.
并且不确定如何进行。
Update 1: I have tried adding the following code to get solve the linker errors. 更新1:我尝试添加以下代码来解决链接器错误。
print("Linking DX12 Libs")
libdirs {
os.findlib("d3d12.lib"),
os.findlib("dxgi.lib"),
os.findlib("d3dcompiler.lib") }
links { "d3d12.lib", "dxgi.lib", "d3dcompiler.lib" }
However, I still get linker errors. 但是,我仍然收到链接器错误。
For the first part of your question, all you need to do is use links in your script. 对于问题的第一部分,您需要做的就是在脚本中使用链接 。 It would look like this:
它看起来像这样:
links
{
"d3d12.lib",
"dxgi.lib",
"d3dcompiler.lib"
}
Above will work if the lib files are in the root directory (where the solution is built). 如果lib文件位于根目录(构建解决方案的目录)中,则以上方法将起作用。 If they are on other folders you can use Tokens like
%{prj.location}
, %{prj.name}
, etc. 如果它们在其他文件夹上,则可以使用令牌,例如
%{prj.location}
, %{prj.name}
等。
DLPDev was mostly* correct. DLPDev主要*是正确的。
*When specifying libraries, system-specific decorations, such as prefixes or file extensions, should be omitted.
*指定库时,应省略系统特定的修饰,例如前缀或文件扩展名。 Premake will synthesize the correct format based on the target platform automatically.
Premake会根据目标平台自动合成正确的格式。 The one exception to the rule is Mac OS X frameworks, where the file extension is required to identify it as such.
该规则的一个例外是Mac OS X框架,其中需要文件扩展名来标识它。
I made a crucial mistake due to my ignorance of the filter function. 由于对过滤器功能的不了解,我犯了一个严重的错误。 Before I had the call to
links
after the release filter. 在发布过滤器之后,我才调用
links
。 Which only linked the dx12 libraries in release mode. 仅在发布模式下链接了dx12库。
-- This is all you need to link against dx12 there is no special sauce
-- You don't need to call libdirs or os.findlib for the dx12 libraries
-- This code works for both configurations since it is called before the filter function
links { "d3d12", "dxgi", "d3dcompiler" }
filter("configurations:Debug")
defines({ "DEBUG" })
symbols("On")
optimize("Off")
filter("configurations:Release")
defines({ "NDEBUG" })
symbols("On")`
TLDR: Be careful not to include file extensions when using the links
function. TLDR:使用
links
功能时,请注意不要包含文件扩展名。 And be careful of the scope of the filter
function 并注意
filter
功能的范围
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.