ios - 体系结构 x86_64 : "_nlist" 的 undefined symbol

标签 ios c xcode ios-simulator x86-64

在我维护的一些 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/

相关文章:

iphone - 在 XCODE 4.2 中崩溃时线程不会停在实际的代码行

ios - 当在 nib 中声明 UITableView 时,UITableViewCell nil IBOutlets

c - 如何在c中返回这个缓冲区值?

c - read() 用于从标准输入读取流

c++ - 通过宏进行元编程

xcode - Xcode 6 中是否有键盘快捷键可以在光标下运行单个当前测试函数?

ios - 滑动时更改 UIslider 缩略图

ios - 在 iCloud Drive 中执行 `NSMetadataQuery` 时出错

ios - UISegmentedControl 在删除段时删除当前选定的段

ios - Swift 如何从源自 lib 的字符串创建类实例