最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - Static linking of Metal library in Xcode - Stack Overflow

programmeradmin0浏览0评论

Status quo: I have an Xcode "Command Line Tool" project written mainly in Swift. In that same project there's a .metal file with some image manipulation code. When I build and archive that project, Xcode produces an executable binary plus a default.metallib library that is needed to run the executable.

What I want to achieve: I want Xcode to produce a single executable binary. The default.metallib should be statically linked.

I tried to add the compiled default.metallib to "Frameworks and Libraries" in the project "General" settings, which also added that lib to "Link Binary With Libraries" in "Build Phases", but that did nothing.

Is this even possible or do I have a completely wrong idea about the whole workflow?

Status quo: I have an Xcode "Command Line Tool" project written mainly in Swift. In that same project there's a .metal file with some image manipulation code. When I build and archive that project, Xcode produces an executable binary plus a default.metallib library that is needed to run the executable.

What I want to achieve: I want Xcode to produce a single executable binary. The default.metallib should be statically linked.

I tried to add the compiled default.metallib to "Frameworks and Libraries" in the project "General" settings, which also added that lib to "Link Binary With Libraries" in "Build Phases", but that did nothing.

Is this even possible or do I have a completely wrong idea about the whole workflow?

Share Improve this question asked Mar 3 at 13:23 limebagellimebagel 213 bronze badges 1
  • What you want is not to link the metallic file into your executable, which makes no sense, but to embed it. Check out this question stackoverflow/questions/34641373/… – Spo1ler Commented Mar 3 at 16:16
Add a comment  | 

1 Answer 1

Reset to default 1

You cannot link the binary with the .metallib file, but you could include the Metal shader source in the source code, using a raw string, and create the library with:

func makeLibrary(
    source: String,
    options: MTLCompileOptions?
) throws -> any MTLLibrary

Reference.

发布评论

评论列表(0)

  1. 暂无评论