Swift3 尝试让swift包示例工作

Swift3 尝试让swift包示例工作,swift3,swift-package-manager,Swift3,Swift Package Manager,我正在学习中的第一个示例 我的设置:macOS 10.12.1,Brew(jpeg-8d和jasper-1.900.21),Swift 3.0.1 说明中没有提到,example/Package.swift需要这一行,否则它将无法生成: name:“示例”, 错误是: /Users/yost/p/swift/package-example/work/example/Package.swift:3:22: error: missing argument for parameter 'name' i

我正在学习
中的第一个示例

我的设置:macOS 10.12.1,Brew(
jpeg-8d
jasper-1.900.21
),Swift 3.0.1

说明中没有提到,
example/Package.swift
需要这一行,否则它将无法生成:
name:“示例”,
错误是:

/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
说明中没有,但根据本文档的章节,我添加了一行
提供程序:[.Brew(“jpeg”)]

转到
CJPEG/Package.swift
并尝试在未安装
jpeg
的情况下构建,而
swift build
不建议运行
brew安装jpeg

应该是这样的。我安装了
brew jpeg
,然后继续

现在brew安装了
jpeg
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
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
我发现我不能只使用:
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/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
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
编译Swift模块“示例”(1个源代码)
:1:9:注意:在文件中包括:1:
#导入“/usr/local/include/jasper/jasper.h”
^
/usr/local/include/jasper/jasper.h:65:10:错误:“未找到jasper/jas_config.h”文件
#包括
^
/Users/yost/p/swift/package example/example/Sources/main.swift:3:8:错误:无法生成Objective-C模块“CJasPer”
导入CJasPer
^
:0:错误:生成有1个命令失败
错误:退出(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-Xcc-I/usr/local/include-Xlinker-L/usr/local/lib

但是我还没有看到我可以添加到
Package.swift中的内容,这样我就可以简单地使用

swift build

它是
-Xcc-I/usr/local/include-Xlinker-L/usr/local/lib


请注意,为了使用不带参数的
swift build
,您可以为您的库指定
.pc
条目。

它是
-Xcc-I/usr/local/include-Xlinker-L/usr/local/lib


请注意,为了在不带参数的情况下使用
swift build
,您可以为您的库指定
.pc
项。

SwiftPM更新了文档,对系统包和新示例进行了更好的解释


SwiftPM更新了文档,对系统包和新示例进行了更好的解释


SwiftPM团队扩展了文档并修复了许多问题(如安基特·阿加瓦尔所说)。

SwiftPM团队扩展了文档并修复了许多问题(如安基特·阿加瓦尔所说)。

我不明白你的答案。你能不能简短一点?我不理解这些:“如果他们有pkg config实用程序的.pc条目”。pkg配置实用程序与swift软件包有什么关系?感谢您澄清我的答案:首先,您可以使用
-Xcc-I/usr/local/include-Xlinker-L/usr/local/lib
@silvalli;其次,如果您想使用
swift build
而不指定标志,您可以为您的库使用
pkgConfig
属性。描述如下:它定义了pkg配置(.pc)文件的名称,该文件应被搜索和读取,以获取其他标志,如包括搜索路径、链接器搜索路径、系统库。。。然而,并非所有系统库都有
.pc
条目。如果他们这样做,
pkgConfig
属性将起作用,如果不起作用-您必须使用
swift build
指定标志我不明白您的答案。你能不能简短一点?我不理解这些:“如果他们有pkg config实用程序的.pc条目”。pkg配置实用程序与swift软件包有什么关系?感谢您澄清我的答案:首先,您可以使用
-Xcc-I/usr/local/include-Xlinker-L/usr/local/lib
@silvalli;其次,如果您想使用
swift build
而不指定标志,您可以为您的库使用
pkgConfig
属性。描述如下:它定义了pkg配置(.pc)文件的名称,该文件应被搜索和读取,以获取其他标志,如包括搜索路径、链接器搜索路径、系统库。。。然而,并非所有系统库都有
.pc
条目。如果这样做,
pkgConfig
属性将起作用,如果不起作用,则必须使用
swift build