gpt4 book ai didi

c - 对 module_open 的 undefined reference

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

我正在研究一些涉及 module_open 函数的 C websocket 编程代码。我收到一个链接器错误,说明了这一点:

/tmp/ccJ3uaHB.o: In function `main':
main.c:(.text+0x8a): undefined reference to `module_open'
collect2: ld returned 1 exit status

该函数在文件server.h中定义为:

extern struct server_module* module_open (const char* module_path);

现在仅包含相关代码,module_open 函数在 main() 中使用,如下所示:

#include <stdio.h>
#include <netdb.h>
#include "server.h"
#include <string.h>

int main()
{
struct server_module* module = NULL;
const char* page;

if(*page == '/' && strchr(page + 1, '/') == NULL)
{
char module_file_name[64];
snprintf(module_file_name, sizeof(module_file_name), "%s.so", page + 1);

/* Try to open the module. */
module = module_open (module_file_name);

}

}

如果它有帮助的话,还有来自server.hstruct module

/* An instance of a loaded server module.  */
struct server_module {
/* The shared library handle corresponding to the loaded module. */
void* handle;
/* A name describing the module. */
const char* name;
/* The function which generates the HTML results for this module. */
void (* generate_function) (int);
};

最佳答案

尝试使用 -ldl 开关进行链接。我认为您正在尝试使用动态加载器库,对吗?

关于c - 对 module_open 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36226968/

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