英文:
How do I fix Xcode build error "no such module 'myModule'" at "import myModule" in my Swift app after adding a swift static lib .a to my swift app?
问题
我有一个Swift应用项目。
我创建并构建了一个Swift静态库,其中包含以下代码:
public func test() {
print("hello world")
}
我在应用项目的“Build Phases”中添加了.a
文件到“Link Binary with Libraries” > (+) > myModule.a
。
我添加了import myModule
并在我的视图控制器中调用了test()
。
然后构建。
出现错误。
英文:
I have a swift app project.
I create and build a swift static lib with
public func test() {
print("hello world")
}
I add .a
to app project Build Phases > Link Binary with Lib.. > (+) > myModule.a
I add import myModule
and a call to test()
in my view controller.
Build.
get error.
答案1
得分: 0
-
.swiftmodule文件必须与.a文件在同一文件夹中。
即在Swift应用项目中,执行Xcode命令以添加文件,然后选择*.a和.swiftmodule文件。 -
构建设置 > "搜索路径" > Swift编译器 - 搜索路径 > 导入路径:必须包含.a文件所在文件夹的路径。
英文:
Was because I failed to add the .swiftmodule to the app and I didn't set Swift Compiler - Search Paths > Import Paths.
-
.swiftmodule file must be in same folder as .a file.
ie. In swift app project, do Xcode command to add files and select BOTH .a and .swiftmodule files. -
Build Settings > "Search Paths" > Swift Compiler - Search Paths > Import Paths: must have path to .a's folder.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论