Search code examples
c++csip

osip library sip errors


On the How-To initialize libosip2 site theres program to initialize osip libraries https://www.gnu.org/software/osip/doc/html/group__howto0__initialize.html

#include <winsock2.h>
#include <Time.h>
#include <stdio.h>
#include <stdlib.h>
#include <osip2/osip.h>
#include <osipparser2/osip_parser.h>
#include <string.h>

int main()
{

    int i;
    osip_t *osip;
    i=osip_init(&osip);
    if (i!=0)

      return -1;
}

I'm trying to run this code but it doesnt work, library version 5.0.0

error:

||=== Build: Debug in cos2 (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Users\emergency\Documents\analizer\cos2\main.cpp|14|undefined reference to `osip_init'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Solution

  • In order to link with a library, you need to specify it on the command line.

    Note that libosip2 produces two libraries and you have to link with both of them in order to use both parser (libosipparser2) and the sip engine (libosip2).

    The exact command line depends on the platform, compiler you use and may also differ if you are linking to a static library or dynamic library.

    With GCC and dynamic linking, it should be that way:

    -L/install-directory-for-libosip2-libs/ -losipparser2 -losip2
    

    -L/install-directory-for-libosip2-libs/ parameter refers to the directory where libraries are available.