gpt4 book ai didi

c - libircclient 中函数的链接问题

转载 作者:行者123 更新时间:2023-11-30 17:59:23 25 4
gpt4 key购买 nike

问题是链接或包含......库 libircclient.h 已找到,但库中使用的函数没有......

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>

/*#include "./libircclient-1.6/include/libircclient.h"*/
#include "libircclient.h"

typedef struct
{
char * channel;
char * nick;

} irc_ctx_t;


void addlog (const char * fmt, ...)
{
FILE * fp; // File-Zeiger
char buf[1024];
va_list va_alist;

va_start (va_alist, fmt);
#if defined (WIN32)
_vsnprintf (buf, sizeof(buf), fmt, va_alist);
#else
vsnprintf (buf, sizeof(buf), fmt, va_alist);
#endif
va_end (va_alist);

printf ("%s\n", buf);

if ( (fp = fopen ("irctest.log", "ab")) != 0 ) // High level, daher File-Zeiger
{
fprintf (fp, "%s\n", buf);
fclose (fp);
}
}


void dump_event (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
char buf[512];
int cnt;

buf[0] = '\0';

for ( cnt = 0; cnt < count; cnt++ )
{
if ( cnt )
strcat (buf, "|");

strcat (buf, params[cnt]);
}


addlog ("Event \"%s\", origin: \"%s\", params: %d [%s]", event, origin ? origin : "NULL", cnt, buf);
}


void event_join (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
dump_event (session, event, origin, params, count);
irc_cmd_user_mode (session, "+i");
irc_cmd_msg (session, params[0], "Hi all");
}


void event_connect (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
dump_event (session, event, origin, params, count);

irc_cmd_join (session, ctx->channel, 0);
}


void event_privmsg (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
dump_event (session, event, origin, params, count);

printf ("'%s' said me (%s): %s\n",
origin ? origin : "someone",
params[0], params[1] );
}

....

gcc irctest.c

/tmp/ccbleNaD.o: In function `event_join': irctest.c:(.text+0x2b9):

undefined reference to `irc_cmd_user_mode' irctest.c:(.text+0x2d4):

undefined reference to `irc_cmd_msg' /tmp/ccbleNaD.o: In function

`event_connect': irctest.c:(.text+0x2fe): undefined reference to

`irc_get_ctx' irctest.c:(.text+0x33b): undefined reference to

irc_cmd_join' /tmp/ccbleNaD.o: In functiondcc_recv_callback':

irctest.c:(.text+0x43c): undefined reference to `irc_dcc_msg'

irctest.c:(.text+0x49b): undefined reference to `irc_dcc_msg'

irctest.c:(.text+0x4a7): undefined reference to `irc_strerror' ....

collect2: ld gab 1 als Ende-Status zurück

最佳答案

编译时,您必须链接到库。它正在查找函数声明,但无法链接到包含定义的目标文件。

我认为它会是这样的:gcc -lircclient irctest.c

关于c - libircclient 中函数的链接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11477266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com