我有一个静态库 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/