ios - 在 XCode 单 View 编译期间获取体系结构 i386 的 undefined symbol

标签 ios objective-c xcode static-libraries

我有一个静态库 X,它位于 C 中。我有另一个静态库 Y,它位于 Objective-C 中,它的 .mm 文件引用库 X 的功能。现在在一个单一 View 应用程序中,我使用了库 Y。
但是在编译期间它给出一个错误说

Undefined symbols for architecture i386:
  "encode()", referenced from:
      _playMediaInternal in libXMedia.a(XMediaInternal.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

上述编码函数存在于库 X 中,库 Y 正在使用该函数,并且单 View 应用程序使用该函数。有什么建议么 ?我已经看到了同一行的其他查询,但没有运气。另一个线程 link

在 Apple 开发者网站上,我一直在尝试使用静态库 link .

我已将手机连接到笔记本电脑并开始对其进行编译。它仍然给我错误。现在我觉得它与链接自身而不是架构有关

最佳答案

我从 stackoverflow 链接 The Answer 得到了答案

我正在粘贴确切的东西。对我来说,问题在于具有基于 C 的函数调用的 header

如果您在 c++ 文件中使用 c 函数。你应该使用 extern "c"{} .
在 .h 文件中

#ifdef __cplusplus
extern "C" {
#endif

swrve_currency_given(parameter1, parameter2, parameter3);// a c function


#ifdef __cplusplus
}
#endif  

extern "C" is meant to be recognized by a C++ compiler and to notify the compiler that the noted function is (or to be) compiled in C style.



如果您要链接到编译为 C 代码的库。采用
extern "C" {
  #include "c_only_header.h"
}

看看When to use extern "C" in C++?

关于ios - 在 XCode 单 View 编译期间获取体系结构 i386 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15985552/

相关文章:

ios - 在 UIButton 状态为 .disabled 时更改其颜色

iOS图像在按下按钮时旋转

objective-c - CocoaPods 与 Swift 项目和 Vuforia

ios - 确认命令未找到错误

ios - 可以在上传前重命名 iOS 应用程序吗?

ios - 以编程方式更改 flutter i18n 应用程序的语言在 iOS 中不起作用

ios - RestKit/核心数据 : Duplicate objects inserted instead of merged when requesting the same URL twice

objective-c - 如何处理 iPad 旋转?

尝试在 testflight 上部署时,iOS 应用程序未显示在 iTunes Connect 上

xcode - 如何修复与我的 NSCollectionView 相关的 'Prototype Segue' (Xcode 7.0 beta)