【问题标题】:nlist function always returns -1nlist 函数总是返回 -1
【发布时间】:2017-02-24 21:57:46
【问题描述】:

我通过编译另一个程序制作了exe文件(d.out)。 nlist 函数总是返回 -1。 fopen 函数返回 !=null。如果重要的话,我会像这样编译我的编 gcc -I/usr/include main.c -L/usr/lib/i386-linux-gnu/pkgconfig -lbsd

#include <string.h>
#include <bsd/nlist.h>
#include  <stdio.h>
#include <stdlib.h>

int test(){
    struct nlist nl[2];
    memset(&nl, 0, sizeof(nl));
    return  nlist("d.out", nl);
//  return nl[0].n_value;
}

int main(){


printf("%d \n", test());

}

【问题讨论】:

    标签: c file bsd


    【解决方案1】:

    我的 FreeBSD 手册页说:

    返回值
    成功则返回无效条目数;否则,如果 文件filename不存在或不可执行,返回值 是-1。

    d.out 存在吗?

    【讨论】:

    • 当然存在。我试图打开它,它返回 !=NULL 。
    • @ArseniyErmilov 当然 x 位没有丢失? file d.out 说它是可执行文件?
    • d.out: ELF 32-bit LSB executable ... -rwxrwxrwx 1 username ...
    • 我运行 gdb。并且在某个时刻在 func nlist gdb 中打印:_dl_runtime_resolve () at ../sysdeps/i386/dl-trampoline.S:35 ../sysdeps/i386/dl-trampoline.S: No such file or catalog。也许因为这个原因它不起作用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-24
    • 2014-03-24
    相关资源
    最近更新 更多