在我维护的一些 iOS 代码中添加 64 位支持时,我发现 nlist函数不适用于 x86_64 架构(64 位 iOS 模拟器)。调用 nlist() 的代码适用于所有其他架构(armv7、armv7s、arm64 和 i386),但无法成功构建 x86_64,其中链接器无法在链接库中找到符号。
它可以在使用 Xcode 创建的模板项目上重现,只需添加:
#import <mach-o/nlist.h>
int testnlist()
{
struct nlist nl[2];
bzero(&nl, sizeof(struct nlist) * 2);
return nlist("test", nl);
}
结果:
Undefined symbols for architecture x86_64:
"_nlist", referenced from: _testnlist in ViewController.o
ld: symbol(s) not found for architecture x86_64
在 Xcode 6.1.1 上使用 iOS SDK 进行测试:8.1,为 iPhone 6 模拟器构建。
在我看来,Apple 可能忘记包含一些为 x86_64 构建的模拟器共享库,但我也可能忽略了一些非常明显的东西......
最佳答案
you might want to try:
#ifndef N_NLIST_DECLARED
struct nlist
{
union
{
char *n_name;
struct nlist *n_next;
long n_strx;
} n_un;
unsigned char n_type;
char n_other;
short n_desc;
unsigned long n_value;
};
#endif
which I extracted from:
<https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/android-4.1.2_r2/lib/gcc/x86_64-linux/4.6.x-google/include-fixed/linux/a.out.h>
in that same header file, you will find lots of other things that
will be 'gotcha's when moving to 64bit code
关于ios - 体系结构 x86_64 : "_nlist" 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27784837/