libyahoo分段故障 [英] libyahoo Segmentation fault

查看:182
本文介绍了libyahoo分段故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这篇code:

 的#include< libyahoo2 / yahoo2.h>
#包括LT&; libyahoo2 / yahoo2_callbacks.h>
诠释主(){
    INT ID;
    字符的用户名[255] =大满贯;
    字符密码[255] =SS;
    ID = yahoo_init(用户名,密码);
    枚举yahoo_status mYahoo;
    mYahoo = YAHOO_STATUS_AVAILABLE;
    yahoo_login(ID,mYahoo);
    返回0;
}

编译它, gcc的-l yahoo2 YC -o雅虎运行./雅虎给我错误:分段故障

 (GDB)运行计划接收信号SIGSEGV,分割过错。
0x001379b1在yahoo_login在libyahoo2.c(ID = 1时,初始= 0):1735

行1735 code是:

 标记= YAHOO_CALLBACK(ext_yahoo_connect_async)(yd-> CLIENT_ID,
        主机,yss-> pager_port,yahoo_connected,CCD,0);

和看到以下内容:

 (GDB)名单YAHOO_CALLBACK
功能YAHOO_CALLBACK没有定义。

如何调试呢?


解决方案

  

如何调试呢?


执行以下命令:

 (GDB)打印yd->的client_id
(GDB)打印yss-> pager_port

我的猜测是,一个或两个以上的命令就会失败,因为 YD YSS 为NULL

如果是这样,问题的较早的在libyahoo2.c,它(显然)不检查错误,正确的。

的原因,你不能列表YAHOO_CALLBACK 是最有可能它是一个宏。看在 libyahoo2 / yahoo2_callbacks.h - 这是极有可能在那里定义

另外,你的链接命令行:

  gcc的-l yahoo2 y.c -o雅虎

完全是伪造的。正确的命令行应该是:

 的gcc -o y.c雅虎-lyahoo2

您可能需要阅读这个解释明白为什么的源代码和库顺序命令行的问题。

I wrote this code:

#include <libyahoo2/yahoo2.h>
#include <libyahoo2/yahoo2_callbacks.h>


int main() {
    int id ;
    char username[255] = "slam";
    char password[255] = "ss" ;
    id = yahoo_init(username, password);
    enum yahoo_status mYahoo ;
    mYahoo = YAHOO_STATUS_AVAILABLE ;
    yahoo_login(id , mYahoo );


    return 0;
}

Compile it, gcc -l yahoo2 y.c -o yahoo and run it with ./yahoo gives me a error: Segmentation fault

(gdb) run

Program received signal SIGSEGV, Segmentation fault.
0x001379b1 in yahoo_login (id=1, initial=0) at libyahoo2.c:1735

line 1735 code is:

tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id,
        host, yss->pager_port, yahoo_connected, ccd, 0);

and see this :

(gdb) list YAHOO_CALLBACK
Function "YAHOO_CALLBACK" not defined.

How do I debug this?

解决方案

How do I debug this?

Execute these commands:

(gdb) print yd->client_id
(gdb) print yss->pager_port

My guess would be that one or both of the above commands will fail, because yd or yss is NULL.

If so, the problem is earlier in libyahoo2.c, and it (apparently) doesn't check for errors properly.

The reason you can't list YAHOO_CALLBACK is most likely that it is a macro. Look in libyahoo2/yahoo2_callbacks.h -- it's very likely to be defined there.

Also, your link command line:

gcc -l yahoo2 y.c -o yahoo

is totally bogus. Correct command line should be:

gcc y.c -o yahoo -lyahoo2

You may want to read this explanation to understand why order of sources and libraries on command line matters.

这篇关于libyahoo分段故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆