简体   繁体   中英

DirectX12 with Premake5: Linking Directx12 Static Libraries

I'm switching to using a premake5 instead of just directly working with Visual Studio 2017.

  • However, I'm having trouble linking against the appropriate dx12 libraries

Here is how I linked against Dx12 in the past. I would put these macros in my main.cpp and it worked great.

    #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.

Apologies I am new to tools like premake5. And am unsure how to proceed.

Update 1: I have tried adding the following code to get solve the linker errors.

    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). If they are on other folders you can use Tokens like %{prj.location} , %{prj.name} , etc.

DLPDev was mostly* correct.

*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. The one exception to the rule is Mac OS X frameworks, where the file extension is required to identify it as such.

I made a crucial mistake due to my ignorance of the filter function. Before I had the call to links after the release filter. Which only linked the dx12 libraries in release mode.

   -- 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. And be careful of the scope of the filter function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM