[asterisk-dev] Problems with custom C-file: undefined reference
Corey Farrell
git at cfware.com
Fri Dec 9 11:42:30 CST 2016
I'm not sure what you're trying to accomplish but this is not the approach
I'd take for expanding chan_sip. My advice is to simply put your system.c
into channels/sip. This will automatically link it into the binary
chan_sip module, but allow you to keep your source code in a separate
file. I believe MODULEINFO (for any added dependencies) and possibly a
call to your init/cleanup would be the only changes you'd need to make in
chan_sip.c. All non-static symbols in chan_sip.c and channels/sip/*.c are
available across all sources of chan_sip.so without needing
chan_sip.exports.in or AST_MODFLAG_GLOBAL_SYMBOLS.
The only exception is if you need to call chan_sip functions from another
existing module, then you will have to export the symbols. To do this you
have to tell the linker (via chan_sip.exports.in) and you have to tell the
module loader. AST_MODULE_INFO at the very end of chan_sip.c would need
AST_MODFLAG_GLOBAL_SYMBOLS so the module loader knows to share the globals:
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS
| AST_MODFLAG_LOAD_ORDER, "Session Initiation Protocol (SIP)",
On Fri, Dec 9, 2016 at 10:50 AM, Julian Fleischhauer <
julian.fleischhauer at stud.uni-due.de> wrote:
> 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
>>
>>
>
> --
> _____________________________________________________________________
> -- 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/5c41cd8c/attachment-0001.html>
More information about the asterisk-dev
mailing list