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?

huangapple go评论49阅读模式
英文:

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

  1. .swiftmodule文件必须与.a文件在同一文件夹中。
    即在Swift应用项目中,执行Xcode命令以添加文件,然后选择*.a和.swiftmodule文件。

  2. 构建设置 > "搜索路径" > Swift编译器 - 搜索路径 > 导入路径:必须包含.a文件所在文件夹的路径。

英文:

Was because I failed to add the .swiftmodule to the app and I didn't set Swift Compiler - Search Paths > Import Paths.

  1. .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.

  2. Build Settings > "Search Paths" > Swift Compiler - Search Paths > Import Paths: must have path to .a's folder.

huangapple
  • 本文由 发表于 2023年3月4日 02:08:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630505.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定