【问题标题】:How to link against CoreGraphics framework from swiftc on command line如何在命令行上从 swiftc 链接 CoreGraphics 框架
【发布时间】:2020-05-08 08:39:17
【问题描述】:

我正在编写一个命令行程序,并且必须使用 CoreGraphics 库

使用原生 swiftc 命令时如何链接 CoreGraphics 框架?

一些背景知识只是为了解释理由:

  1. 我正在尝试使用 Apple MPS 库执行 MPSMatrix 操作(即计算操作)。

  2. 我喜欢在编写非常简单的实验时使用本机命令行进行开发,以避免陷入工具集(例如 xcode、swift 包)中

  3. Apple 文档 here 指出,即使在简单的命令行工具中,您也需要链接 CoreGraphics 框架才能使用 MPS

  4. swiftc 命令似乎会自动引入 Foundation、Metal 等,但似乎无法自动找到并链接 CoreGraphics 框架。

我目前正在使用的程序是:

import CoreGraphics
import Metal
import Foundation
import Accelerate
import MetalPerformanceShaders

guard let device = MTLCreateSystemDefaultDevice() else {
    fatalError( "Failed to get the system's default Metal device." )
}

let N = 1000000

// Create a Metal buffer of length N
let buffer = device.makeBuffer(length: N * MemoryLayout<Float32>.size)

// Create a vector descriptor
let descriptor = MPSVectorDescriptor(length: N, dataType: .float32)

// Create a vector with descriptor
let vector = MPSVector(buffer: buffer!, descriptor: descriptor)

目前 MTLCreateSystemDefaultDevice() 调用失败,我认为这是因为我没有链接 CoreGraphics 框架 - 所以这就是问题 - 如何从命令行链接它。

【问题讨论】:

    标签: swift core-graphics


    【解决方案1】:

    好的,所以我继续试验,最终只是复制了 clang 的命令结构。 (非常简单的答案)是:

    swiftc -framework CoreGraphics myprog.swift
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 2019-01-11
      • 2011-09-22
      • 2021-12-02
      • 1970-01-01
      相关资源
      最近更新 更多