Linking C-API functions, when using pjsua2

PG
Piewald Georg
Sun, Sep 18, 2016 11:54 AM

Hi,
I found a problem in pjsua2/config.hpp. This file includes pjsua-lib/pjsua.h without an extern "C" declaration. This makes it impossible to call any of the C-API functions, if I otherwise use the pjsua2 API, because they are connected through this include-chain:
pjsua2.hpp
-> ... (any of those)
-> pjsua2/persistent.hpp
-> pjsua2/types.hpp
-> pjsua2/config.hpp
-> pjsua-lib/pjsua.h

So I guess that's a bug? The fix would be simple:
extern "C" {
#include <pjsua-lib/pjsua.h>
}

BR, Georg

Hi, I found a problem in pjsua2/config.hpp. This file includes pjsua-lib/pjsua.h without an extern "C" declaration. This makes it impossible to call any of the C-API functions, if I otherwise use the pjsua2 API, because they are connected through this include-chain: pjsua2.hpp -> ... (any of those) -> pjsua2/persistent.hpp -> pjsua2/types.hpp -> pjsua2/config.hpp -> pjsua-lib/pjsua.h So I guess that's a bug? The fix would be simple: extern "C" { #include <pjsua-lib/pjsua.h> } BR, Georg
WD
Walter Doekes
Mon, Sep 19, 2016 7:01 AM

On 18-09-16 13:54, Piewald Georg wrote:

So I guess that’s a bug? The fix would be simple:

extern "C" {
#include <pjsua-lib/pjsua.h>
}

That construct looks odd. Generally I'd expect the .h header to include
the extern part not the caller of the include. See any header in
/usr/include (nowadays perhaps using a __BEGIN_DECLS macro).

And that's what I find inside a sample pjsip/sip_auth.h on my system:

It starts with PJ_BEGIN_DECL, and that in turn is defined as:

/**

  • @def PJ_END_DECL
  • Mark end of declaration section in a header file.
    */
    #ifdef __cplusplus

define PJ_DECL_NO_RETURN(type)  PJ_DECL(type) PJ_NORETURN

define PJ_IDECL_NO_RETURN(type)  PJ_INLINE(type) PJ_NORETURN

define PJ_BEGIN_DECL            extern "C" {

define PJ_END_DECL              }

#else

define PJ_DECL_NO_RETURN(type)  PJ_NORETURN PJ_DECL(type)

define PJ_IDECL_NO_RETURN(type)  PJ_NORETURN PJ_INLINE(type)

define PJ_BEGIN_DECL

define PJ_END_DECL

#endif

Greetings,
Walter

On 18-09-16 13:54, Piewald Georg wrote: > So I guess that’s a bug? The fix would be simple: > > extern "C" { > #include <pjsua-lib/pjsua.h> > } That construct looks odd. Generally I'd expect the .h header to include the extern part not the caller of the include. See any header in /usr/include (nowadays perhaps using a __BEGIN_DECLS macro). And that's what I find inside a sample pjsip/sip_auth.h on my system: It starts with PJ_BEGIN_DECL, and that in turn is defined as: /** * @def PJ_END_DECL * Mark end of declaration section in a header file. */ #ifdef __cplusplus # define PJ_DECL_NO_RETURN(type) PJ_DECL(type) PJ_NORETURN # define PJ_IDECL_NO_RETURN(type) PJ_INLINE(type) PJ_NORETURN # define PJ_BEGIN_DECL extern "C" { # define PJ_END_DECL } #else # define PJ_DECL_NO_RETURN(type) PJ_NORETURN PJ_DECL(type) # define PJ_IDECL_NO_RETURN(type) PJ_NORETURN PJ_INLINE(type) # define PJ_BEGIN_DECL # define PJ_END_DECL #endif Greetings, Walter
PG
Piewald Georg
Mon, Sep 19, 2016 7:23 AM

Ok, makes sense. However, the problem is somewhere else then, since I cannot not link the function pjmedia_type_name(). I would say that in pjmedia/include/pjmedia/types.h the PJ_BEGIN_DECL and PJ_END_DECL are missing?

BR Georg

-----Original Message-----
From: pjsip [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Walter Doekes
Sent: Monday, September 19, 2016 09:02
To: pjsip list pjsip@lists.pjsip.org
Subject: Re: [pjsip] Linking C-API functions, when using pjsua2

On 18-09-16 13:54, Piewald Georg wrote:

So I guess that's a bug? The fix would be simple:

extern "C" {
#include <pjsua-lib/pjsua.h>
}

That construct looks odd. Generally I'd expect the .h header to include the extern part not the caller of the include. See any header in /usr/include (nowadays perhaps using a __BEGIN_DECLS macro).

And that's what I find inside a sample pjsip/sip_auth.h on my system:

It starts with PJ_BEGIN_DECL, and that in turn is defined as:

/**

  • @def PJ_END_DECL
  • Mark end of declaration section in a header file.
    */
    #ifdef __cplusplus

define PJ_DECL_NO_RETURN(type)  PJ_DECL(type) PJ_NORETURN

define PJ_IDECL_NO_RETURN(type)  PJ_INLINE(type) PJ_NORETURN

define PJ_BEGIN_DECL            extern "C" {

define PJ_END_DECL              }

#else

define PJ_DECL_NO_RETURN(type)  PJ_NORETURN PJ_DECL(type)

define PJ_IDECL_NO_RETURN(type)  PJ_NORETURN PJ_INLINE(type) #  define PJ_BEGIN_DECL #  define PJ_END_DECL #endif

Greetings,
Walter


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Ok, makes sense. However, the problem is somewhere else then, since I cannot not link the function pjmedia_type_name(). I would say that in pjmedia/include/pjmedia/types.h the PJ_BEGIN_DECL and PJ_END_DECL are missing? BR Georg -----Original Message----- From: pjsip [mailto:pjsip-bounces@lists.pjsip.org] On Behalf Of Walter Doekes Sent: Monday, September 19, 2016 09:02 To: pjsip list <pjsip@lists.pjsip.org> Subject: Re: [pjsip] Linking C-API functions, when using pjsua2 On 18-09-16 13:54, Piewald Georg wrote: > So I guess that's a bug? The fix would be simple: > > extern "C" { > #include <pjsua-lib/pjsua.h> > } That construct looks odd. Generally I'd expect the .h header to include the extern part not the caller of the include. See any header in /usr/include (nowadays perhaps using a __BEGIN_DECLS macro). And that's what I find inside a sample pjsip/sip_auth.h on my system: It starts with PJ_BEGIN_DECL, and that in turn is defined as: /** * @def PJ_END_DECL * Mark end of declaration section in a header file. */ #ifdef __cplusplus # define PJ_DECL_NO_RETURN(type) PJ_DECL(type) PJ_NORETURN # define PJ_IDECL_NO_RETURN(type) PJ_INLINE(type) PJ_NORETURN # define PJ_BEGIN_DECL extern "C" { # define PJ_END_DECL } #else # define PJ_DECL_NO_RETURN(type) PJ_NORETURN PJ_DECL(type) # define PJ_IDECL_NO_RETURN(type) PJ_NORETURN PJ_INLINE(type) # define PJ_BEGIN_DECL # define PJ_END_DECL #endif Greetings, Walter _______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@lists.pjsip.org http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org