0

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)) ===|
cthulhu
  • 55
  • 4
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – KIIV Dec 20 '16 at 07:51
  • 1
    I guess: you are not linking osip libraries: post your [tag:gcc] command with options – LPs Dec 20 '16 at 07:51
  • i use codeblocks, mingw32-g++.exe -LC:\Lib\WpdPack\Include -o bin\Debug\main_osip2.exe obj\Debug\main.o obj\Debug\main.o: In function `main': C:/Users/emergency/Documents/analizer/main_osip2/main.cpp:15: undefined reference to `osip_init' collect2.exe: error: ld returned 1 exit status – cthulhu Dec 20 '16 at 08:05
  • @cthulhu 1) Please post the command you used in the original post. 2) Where do you actually state what library to link to? The `-L` command AFAIK specifies the library directory, not the library. – PaulMcKenzie Dec 20 '16 at 08:19

2 Answers2

1

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.

AymericM
  • 1,645
  • 13
  • 13
0

this is because you did not link the binary osip.o

LeoChu
  • 726
  • 6
  • 6