我有一个包含C静态库的Swift框架。该框架在iOS应用中使用。
如果我对框架进行了carthage archive
的操作,则将输出放入一个单独的Xcode项目中的应用程序中,然后当它尝试编译该应用程序时,会在CompileSwift
命令中将其驳回:
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "my_sdk.h"
^
/Users/myUser/my-swift-sdk/ext/my-c-sdk/include/c_sdk.h:10:10: note: in file included from /Users/myUser/my-swift-sdk/ext/my-c-sdk/include/c_sdk.h:10:
#include "alpha/alpha.h"
^
/Users/myUser/my-swift-sdk/ext/my-c-sdk/include/alpha/alpha.h:12:10: note: in file included from /Users/myUser/my-swift-sdk/ext/my-c-sdk/include/alpha/alpha.h:12:
#include "../bravo/bravo.h"
^
/Users/myUser/my-swift-sdk/ext/my-c-sdk/include/alpha/../bravo/bravo.h:13:10: error: 'omega.h' file not found
#include "omega.h"
^
<unknown>:0: error: could not build Objective-C module 'libMyCSdk'
0 swift 0x000000010680664a PrintStackTraceSignalHandler(void*) + 42
1 swift 0x0000000106805dfe SignalHandler(int) + 302
2 libsystem_platform.dylib 0x00007fff60ee7b3d _sigtramp + 29
3 libsystem_platform.dylib 0x0000000100020812 _sigtramp + 2668858610
4 swift 0x0000000103f7a197 swift::GenericSignatureBuilder::addRequirement(swift::Requirement const&, swift::GenericSignatureBuilder::FloatingRequirementSource, swift::ModuleDecl*) + 887
5 swift 0x0000000104005922 substType(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolType*)>, swift::SubstOptions) + 2882
6 swift 0x0000000104011318 swift::TypeBase::getTypeOfMember(swift::ModuleDecl*, swift::ValueDecl const*, swift::Type) + 168
7 swift 0x0000000103b01582 swift::CalleeCandidateInfo::CalleeCandidateInfo(swift::Type, llvm::ArrayRef<swift::constraints::OverloadChoice>, bool, swift::constraints::ConstraintSystem&, bool) + 1122
8 swift 0x0000000103a90b2c (anonymous namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) + 10828
9 swift 0x0000000103a6e206 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 70
10 swift 0x0000000103aa15af swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 6207
11 swift 0x0000000103ba644a swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 122
12 swift 0x0000000103ba6b27 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1207
13 swift 0x0000000103a7ee5c (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*, bool) + 1516
14 swift 0x0000000103a76a40 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 25280
15 swift 0x0000000103a6e206 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 70
16 swift 0x0000000103aa15af swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 6207
17 swift 0x0000000103ba644a swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 122
18 swift 0x0000000103ba6b27 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1207
19 swift 0x0000000103c3e9ac swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 12044
20 swift 0x0000000103c3abbe swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 1294
21 swift 0x0000000103c40468 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 888
22 swift 0x0000000103c67013 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 2515
23 swift 0x00000001038a1865 swift::CompilerInstance::performSema() + 4949
24 swift 0x0000000102a8e59b performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 731
25 swift 0x0000000102a8adc5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7717
26 swift 0x0000000102a30a35 main + 1349
27 libdyld.dylib 0x00007fff60cfe085 start + 1
Stack dump:
0. Program arguments: [The stuff sent to SwiftCompile - lots to redact so will add if required]
1. While type-checking 'addDevice()' at /Users/myUser/my-app/Sources/Views/MyView1/MyView1ViewController.swift:54:13
2. While type-checking statement at [/Users/myUser/my-app/Sources/Views/MyView1/MyView1ViewController.swift:54:30 - line:94:5]
[code and some more 'While type-checking expression']
error: Segmentation fault: 11
由于它不是一个开源项目,所以我不得不对其进行修改/更改路径,但是所有重要的东西都应该存在。
如果我在Xcode中编译框架,然后将生成的二进制文件复制到应用程序的Carthage目录中,则不会发生这种情况;该应用程序构建良好。框架的大小不同,但这是可以预期的,因为迦太基将为sim和设备创建一个胖二进制文件,而Xcode生成的一个只会做一个或另一个。
我试图让迦太基在Debug配置中进行构建和存档;这也不起作用(调试将包括进行任何优化/剥离)。
编辑:使用该框架的iOS应用仅在构建模拟器时中断。如果我为该设备构建设备,那很好。
编辑:我尝试了有关在命令行中使用xcodebuild时添加目标的建议here,即xcodebuild clean build -scheme App -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8'
-不起作用。
编辑:为了明确说明,我也对DerivedData进行了几次:)
编辑:环境为Xcode 10.0,在Mojave上使用iOS 12 SDK构建
编辑:标题已更改,以反映新的研究成果。迦太基是红鲱鱼。问题是这样的:
编辑:成功!如果我将“ Header Search Paths”指向我的C静态库的include目录,然后在其中重命名module.modulemap文件,则所有文件都会编译。这不是解决方案,但要确认App项目是否需要标头才能创建模块的缓存版本。
答案 0 :(得分:0)
您在C项目中的标头如何组织?
如果他们有这种模式:
Lib/
Umbrella.h
A/
A1.h
A2.h
B/
B1.h
B2.h
然后,您将需要执行特殊的标头复制阶段,而不仅仅是正常的阶段,因为在这种情况下,一旦复制到框架中,相对于它们的相对路径就很重要。