首页 文章

架构x86_64的未定义符号:“_ nlist”

提问于
浏览
2

在我维护的一些iOS代码中添加64位支持时,我发现nlist函数不适用于x86_64架构(64位iOS模拟器) . 代码调用nlist()适用于所有其他arch(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);
}

结果是:

体系结构x86_64的未定义符号:“_ nlist”,引用自:ViewController.o中的_testnlist ld:未找到体系结构x86_64的符号

使用iOS SDK:8.1测试Xcode 6.1.1,为iPhone 6模拟器构建 .

在我看来,苹果可能已经忘记包含一些为x86_64构建的模拟器共享库,但我可能也会忽略一些明显的愚蠢......

1 回答

  • 0
    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
    

相关问题