[asterisk-dev] Problems with custom C-file: undefined reference

Julian Fleischhauer julian.fleischhauer at stud.uni-due.de
Fri Dec 9 09:50:56 CST 2016


I could resolve the XML and pcap issues, but still have problems concerning
"sip_get_header()". I don't want to rename the function since it's a
frequently used function in chan_sip.c, I therefore defined an .exports.in
file. I don't know if Mr. Michelson understood me correctly, but I think
chan_sip.c exports "sip_get_header()" (doesn't it?) so I modified
*chan_sip.exports.in
<http://chan_sip.exports.in>* so it looks like
{
global:
LINKER_SYMBOL_PREFIXsip_get_header;            // I also tried
LINKER_SYMBOL_PREFIXsip_*;
LINKER_SYMBOL_PREFIX_IO_stdin_used;
local:
*;
};
But it doesn't work. I did the same with *system.exports.in
<http://system.exports.in>*, without success.


Sorry for the badly formatted last mail. I will post the updated file
structure again below.

*sip.h*
const char *sip_get_header(const struct sip_request *req, const char *name);

*system.h*
#include "asterisk/netsock2.h"

void ast_some_function(struct sip_pvt *p, struct ast_sockaddr *addr);

*system.c*
#include "asterisk/system.h"
#include "asterisk/sip.h"

void ast_some_function(struct sip_pvt *p, struct ast_sockaddr *addr)
{
   ast_copy_string(touser, sip_get_header(req, "To"),
strlen(sip_get_header(req, "To")) + 1);
}

*chan_sip.c*
#include "asterisk/system.h"
#include "asterisk/sip.h"

ast_some_function(p, addr);


Best regards,
Julian Fleischhauer

2016-12-06 18:35 GMT+01:00 Mark Michelson <mmichelson at digium.com>:

> On 12/05/2016 04:53 PM, Julian Fleischhauer wrote:
>
>> Hey all,
>>
>> I have a problem using a custom C-file. The error ouput received when
>> compiling is given below.
>>
>> error output
>> .../system.c:1330: undefined reference to `XML_ParserCreate'
>> ...
>> .../system.c:1465: undefined reference to `sip_get_header'
>> ...
>> .../system.c:1608: undefined reference to `pcap_lookupnet'
>> ...
>>
>>
>> Before, I had all code in chan_sip.c. I want to transfer the code into a
>> separate file (system.c) now. The dependencies given below MODULEINFO are
>> customly set and worked fine when used in chan_sip.c. Can anyone figure out
>> if something else has to be added somewhere? The code is quoted below:
>>
>> sip.h
>> const char *sip_get_header(const struct sip_request *req, const char
>> *name);
>>
>> system.h
>> #include "asterisk/netsock2.h"
>>
>> void ast_some_function(struct sip_pvt *p, struct ast_sockaddr *addr);
>>
>> system.c
>> /*** MODULEINFO
>>      <depend>sqlite3</depend>
>>      <depend>expat</depend>
>>      <depend>pcap</depend>
>>     <support_level>extended</support_level>
>> ***/
>>
>> #include "asterisk/system.h"
>> #include "asterisk/sip.h"
>>
>> void ast_some_function(struct sip_pvt *p, struct ast_sockaddr *addr)
>> {
>>     xmlParser = XML_ParserCreate(NULL);
>>    ...
>>    ast_copy_string(touser, sip_get_header(req, "To"),
>> strlen(sip_get_header(req,       "To"))+1);
>>    ...
>>    pcap_lookupnet(pcapDev, &netp, &maskp, errbuf);
>> }
>>
>> chan_sip.c
>> #include "asterisk/system.h"
>> #include "asterisk/sip.h"
>>
>> ast_some_function(p, addr);
>>
>>
>> Thank you for any help!
>>
>> Regards,
>> Juliannn
>>
>> I can explain why sip_get_header() is causing a problem. In order for
> functions to be callable from other modules, they need to be explicitly
> exported. This is why you'll see files like res/res_agi.exports.in, which
> define functions that can be called globally from that module. You have a
> couple of options here:
>
> * Define a .exports.in file for your system.c file that exports the
> sip_get_header() function.
> * Change "sip_get_header()" to "ast_sip_get_header()". Assuming that
> system.c is in the main/ directory, there is a project-wide exports file
> that makes it so any function starting with "ast" can be called externally.
>
> Regarding the XML and pcap issues, the issues are either that
> * You're not #including the necessary files.
> * The libraries are not being linked during compilation.
>
> The first problem is easy to fix: just #include the right files :). The
> second problem is a bit more tricky because you'll need to dig into
> Makefiles and try to figure out how libraries get linked when Asterisk is
> built.
>
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> asterisk-dev mailing list
> To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20161209/75d7f21e/attachment.html>


More information about the asterisk-dev mailing list