无法构建Objective-C模块' CGtk'

时间:2017-04-09 11:29:00

标签: linux swift gtk

我正在尝试在archlinux中使用swift。在尝试使用Gtk构建一个简单的项目时,我遇到了一些错误。下面是我的Package.swift文件:

import PackageDescription

let package = Package(
    name: "SwiftGtkApplication",
    dependencies: [
        .Package(url: "https://github.com/TomasLinhart/SwiftGtk", majorVersion: 0, minor: 2)
    ]
)

main.swift文件:

import SwiftGtk

let app = Application(applicationId: "com.example.application")
app.run { window in
    window.title = "Hello World"
    window.defaultSize = Size(width: 400, height: 400)
    window.resizable = true

    let button = Button(label: "Press Me")
    button.clicked = { _ in
        let newWindow = Window(windowType: .topLevel)
        newWindow.title = "Just a window"
        newWindow.defaultSize = Size(width: 200, height: 200)
        let labelPressed = Label(text: "Oh, you pressed the button.")
        newWindow.add(labelPressed)

        newWindow.showAll()
    }

    window.add(button)
}

我无法使用swift build构建它:

/tmp/swift/.build/checkouts/SwiftGtk--3711260948702777640/Sources/Window.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:

(...)

/tmp/swift/.build/checkouts/SwiftGtk--3711260948702777640/Sources/Window.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<unknown>:0: error: build had 1 command failures
swift-build: error: exit(1): /usr/bin/swift-build-tool -f /tmp/swift/.build/debug.yaml

安装了gtk和clang。我做错了什么?

1 个答案:

答案 0 :(得分:1)

这很简单,可以使用以下命令正确指向SPM文件中的CGtk项目:

.Package(url: "https://github.com/TomasLinhart/CGtk-Linux", majorVersion: 1, minor: 3),