无法构建自定义星号PJSIP模块



我正在尝试创建一个自定义的Asterisk PJSIP模块,它可以:

  • 1( 分析传入的 SIP 消息
  • 2( 将信息从 SIP 标头打印到日志/控制台

这是我的代码(简化(:

 #include "asterisk.h"
ASTERISK_REGISTER_FILE()
#ifndef AST_MODULE
#define AST_MODULE "res_modul"
#endif
//bunch of libraries here
static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata);
static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)
{
    char *method;
    method= rdata->pkt_info.packet;
    ast_log(LOG_NOTICE,"SIP METHOD is: %.8s n",method);

        return PJ_SUCCESS;
}


static pjsip_module logging_module = {
    .name = { "Test module", 20 },
    .priority = 0,
    .on_rx_request = logging_on_rx_msg,
    .on_rx_response = logging_on_rx_msg,
};

static int load_module(void)
{
     CHECK_PJSIP_MODULE_LOADED();
    ast_log(AST_LOG_WARNING, "Success in loading!");
    ast_sip_register_service(&logging_module);
    return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
    ast_sip_unregister_service(&logging_module);
    return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Test module",
    .support_level = AST_MODULE_SUPPORT_EXTENDED,
    .load = load_module,
    .unload = unload_module,
    .load_pri = AST_MODPRI_DEFAULT,
);

当我尝试用我的模块编译Asterisk时,我收到一个编译错误:

menuselect/menuselect --check-deps menuselect.makeopts
   [CC] res_modul.c -> res_modul.o
   [LD] res_modul.o -> res_modul.so
   [LD] res_pjsip.o res_pjsip/security_events.o res_pjsip/pjsip_options.o res_pjsip/location.o res_pjsip/config_global.o res_pjsip/pjsip_transport_events.o res_pjsip/presence_xml.o res_pjsip/pjsip_resolver.o res_pjsip/config_system.o res_pjsip/config_domain_aliases.o res_pjsip/config_transport.o res_pjsip/pjsip_distributor.o res_pjsip/pjsip_configuration.o res_pjsip/res_modul.o res_pjsip/pjsip_session.o res_pjsip/pjsip_message_filter.o res_pjsip/pjsip_global_headers.o res_pjsip/pjsip_transport_management.o res_pjsip/pjsip_cli.o res_pjsip/config_auth.o res_pjsip/pjsip_scheduler.o -> res_pjsip.so
res_pjsip/res_modul.o: In function `__internal_res_pjsip_self':
/usr/local/src/asterisk-14.7.6/res/res_pjsip/res_modul.c:136: multiple definition of `__internal_res_pjsip_self'
res_pjsip.o:/usr/local/src/asterisk-14.7.6/res/res_pjsip.c:4918: first defined here
collect2: error: ld returned 1 exit status

我不知道是什么原因造成的,源代码中没有"__internal_res_pjsip_self"的定义。不在我的模块中,不在 res_pjsip.c 文件中。根据编译错误,它在 res_pjsip.c:4918 中定义,但该行只是AST_MODULE_INFO。

>AST_MODULE_INFO是返回您引用代码的函数的宏。

阅读有关 C 预处理和调试的更多信息

相关内容

  • 没有找到相关文章

最新更新