首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用SwiftPM导出公共C头

用SwiftPM导出公共C头
EN

Stack Overflow用户
提问于 2020-08-02 01:00:04
回答 1查看 1.5K关注 0票数 5

我有一个开源的Objective框架,我也想使用Swift软件包管理器提供这个框架。

通常,我在Xcode项目中设置了公共标头,在构建框架时,会在框架包下复制该文件头,并在Xcode链接到它时被发现。

但是,我不能让它与SwiftPM一起工作。

我为我的框架创建了一个模块地图:

代码语言:javascript
复制
framework module LNPopupController {
    umbrella header "LNPopupController.h"
    export *
    module * { export * }
}

我在Package.swift中像这样定义了库:

代码语言:javascript
复制
let package = Package(
    name: "LNPopupController",
    platforms: [
        .iOS(.v12),
        .macOS(.v10_15)
    ],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "LNPopupController",
            type: .dynamic,
            targets: ["LNPopupController"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "LNPopupController",
            dependencies: [],
            path: "LNPopupController",
            publicHeadersPath: ".",
            cSettings: [
                .headerSearchPath("."),
                .headerSearchPath("Private"),
            ]),
    ]
)

在Xcode中作为项目依赖项添加时,框架编译得很好,但是当依赖目标尝试import LNPopupController时,会引发一个错误:umbrella header 'LNPopupController.h' not found

实际上,查看build文件夹,我看到Xcode构建了一个二进制文件,但没有复制公共标题。

是否可以指定哪些标头是公共的,并使构建系统复制它们以供导入?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-03 22:05:13

我终于想出来了。这就是我为LNPopupController所做的

我创建了一个include/LNPopupController/子目录树,并将软链接放在那里的所有公共标题上。

在包文件中,我添加了publicHeadersPath: "include"

您可以在这里看到最终结果:https://github.com/LeoNatan/LNPopupController/blob/master/Package.swift

这可能不是最理想的方法,但它适用于我尝试过这种方法的所有ObjC项目。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63211415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档