我正在研究swift-package-manager/Documentation/Usage.md
我的设置:macOS 10.12.1,Brew(jpeg-8d
和jasper-1.900.21
),Swift 3.0.1
说明中未提及example/Package.swift
需要此行或不会构建:
name: "example",
错误是:
/Users/yost/p/swift/package-example/work/example/Package.swift:3:22: error: missing argument for parameter 'name' in call
let package = Package(
^
PackageDescription.Package:18:12: note: 'init(name:pkgConfig:providers:targets:dependencies:exclude:)' declared here
public init(name: String, pkgConfig: String? = default, providers: [PackageDescription.SystemPackageProvider]? = default, targets: [PackageDescription.Target] = default, dependencies: [PackageDescription.Package.Dependency] = default, exclude: [String] = default)
^
Can't parse Package.swift manifest file because it contains invalid format. Fix Package.swift file format and try again.
error: invalid manifest format
这不在说明中,但根据本文件的Reference部分,我添加了行
providers: [ .Brew("jpeg") ]
到CJPEG/Package.swift
并尝试在未安装jpeg
的情况下进行构建,swift build
未建议运行
brew install jpeg
因为它应该。我做了brew install jpeg
并继续前进。
现在安装了jpeg
brew,swift build
出现了这些错误:
Compile Swift Module 'example' (1 sources)
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "/usr/local/include/jpeglib.h"
^
/usr/local/include/jpeglib.h:755:3: error: unknown type name 'size_t'
size_t free_in_buffer; /* # of byte spaces remaining in buffer */
^
... blah blah ...
<unknown>:0: error: build had 1 command failures
error: exit(1): /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swift-build-tool -f /Users/yost/p/swift/package-example/example/.build/debug.yaml
我发现我必须编辑/usr/local/include/jpeglib.h
才能添加
#include <stdio.h>
在顶部。
BTW,CJPEG/module.modulemap
文件说:
header "/usr/include/jpeglib.h"
jpeglib.h
文件位于/usr/local/include
,而不是/usr/include
。为什么这不会导致构建错误?
无论如何,此时swift build
出现了这些构建错误:
Compile Swift Module 'example' (1 sources)
Linking ./.build/debug/example
ld: library not found for -ljpeg for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swift-build-tool -f /Users/yost/p/swift/package-example/example/.build/debug.yaml
我发现我不能只用以下方式构建:
swift build
我必须建立与
swift build -Xlinker -L/usr/local/include
这些调整让我了解了jpeglib
示例。
当构建JasPer
示例时,我收到了以下错误:
Compile Swift Module 'example' (1 sources)
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "/usr/local/include/jasper/jasper.h"
^
/usr/local/include/jasper/jasper.h:65:10: error: 'jasper/jas_config.h' file not found
#include <jasper/jas_config.h>
^
/Users/yost/p/swift/package-example/example/Sources/main.swift:3:8: error: could not build Objective-C module 'CJasPer'
import CJasPer
^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swift-build-tool -f /Users/yost/p/swift/package-example/example/.build/debug.yaml
感谢Vadim的回答,我现在知道我必须建立起来
swift build -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib
但我还没有看到我可以添加到Package.swift
的内容,以便我可以简单地使用
构建
swift build
答案 0 :(得分:3)
SwiftPM更新了文档,更好地解释了系统包和一个新的例子。
答案 1 :(得分:0)
是-Xcc -I/usr/local/include -Xlinker -L/usr/local/lib
。
请注意,为了使用不带参数的swift build
,您可以为您的库指定pkgConfig
property,如果它们有pkg-config utility的.pc
条目。
答案 2 :(得分:0)
SwiftPM团队扩展了Swift Packages文档并修复了很多问题(正如Ankit Agarwal所说)。