我正在尝试创建一个可以的自定义Asterisk PJSIP模块:
这是我的代码(简化):
#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。
答案 0 :(得分:0)
AST_MODULE_INFO是宏,它返回您引用代码的函数。
阅读有关C预处理和调试的更多信息