对于Linux,我属于半路出家。编译一个sip,也是一波三折;步骤一一记录如下

开发环境:ubuntu

1.下载sip库:libeXosip2-3.6.0.tar.gz  libosip2-3.6.0.tar.gz

下载地址:http://download.savannah.gnu.org/releases/exosip/


2.编译

解压以后,出现两个文件夹:


然后进行编译,一句一句执行,先切换到目标文件夹,在configure,在make,在make install,如下:

cd libosip2-3.6.0 
./configure
make
make install

cd libeXosip2-3.6.0
./configure --disable-openssl
make
make install

3.一个简单的demo

main.cpp

#include <eXosip2/eXosip.h>

int main()
{
	int i=0;
	i=eXosip_init();
	if(i!=0)
          return -1;
	printf("=========  %s",eXosip_get_version());//打印当前sip库的版本号
	getchar();
	return 0;
}

3.1编译(调用sip动态库):

g++ main.cpp -o main -leXosip2 -losip2  -losipparser2

运行(因为sip编译完的动态库在/usr/local/lib目录下):

LD_LIBRARY_PATH=/usr/local/lib ./main

3.2编译(调用sip静态库):

编译完的sip库的静态库也在/usr/local/lib目录下,我把他们考了出来,放在了工程目录的lib目录下

然后编译

g++ -pthread src/main.cpp -o main -L./lib -leXosip2 -losip2  -losipparser2 -lresolv

执行:

./main

运行结果



完成!

==============================================分割线===================================================

看上去好像很简单?但是却废了咱不少功夫。

首先,是编译,自然是想到:g++ main.cpp -o main   就OK了,可结果呢,报错:找不到函数undefined reference to `eXosip_init'


其次,是运行,直接

./main
不行,报错:./main: error while loading shared libraries: libeXosip2.so.7: cannot open shared object file: No such file or directory

找动态库...


再次,好吧,解决了动态库;就想,为何不能用静态库呢,多方便哪?代价就是又要花时间来研究一番

网上看了一番,知道了g++ -L <目录>  是加载目录下的说有静态库,于是来了一句

g++ src/main.cpp -o main -L./lib -leXosip2 -losip2  -losipparser2
结果又是一顿报错:

./lib/libeXosip2.a(eXutils.o): In function `_eXosip_dnsutils_srv_lookup':
/jiang/workspace/siplib/libeXosip2-3.6.0/src/eXutils.c:3040: undefined reference to `__res_query'
/jiang/workspace/siplib/libeXosip2-3.6.0/src/eXutils.c:3056: undefined reference to `__dn_expand'
/jiang/workspace/siplib/libeXosip2-3.6.0/src/eXutils.c:3074: undefined reference to `__dn_expand'
/jiang/workspace/siplib/libeXosip2-3.6.0/src/eXutils.c:3159: undefined reference to `__dn_expand'
./lib/libeXosip2.a(eXutils.o): In function `eXosip_dnsutils_naptr_lookup':
/jiang/workspace/siplib/libeXosip2-3.6.0/src/eXutils.c:3252: undefined reference to `__res_query'
/jiang/workspace/siplib/libeXosip2-3.6.0/src/eXutils.c:3284: undefined reference to `__dn_expand'
/jiang/workspace/siplib/libeXosip2-3.6.0/src/eXutils.c:3314: undefined reference to `__dn_expand'
/jiang/workspace/siplib/libeXosip2-3.6.0/src/eXutils.c:3397: undefined reference to `__dn_expand'
./lib/libosip2.a(port_sema.o): In function `osip_sem_init':
/jiang/workspace/siplib/libosip2-3.6.0/src/osip2/port_sema.c:170: undefined reference to `sem_init'
./lib/libosip2.a(port_sema.o): In function `osip_sem_destroy':
/jiang/workspace/siplib/libosip2-3.6.0/src/osip2/port_sema.c:182: undefined reference to `sem_destroy'
./lib/libosip2.a(port_sema.o): In function `osip_sem_post':
/jiang/workspace/siplib/libosip2-3.6.0/src/osip2/port_sema.c:193: undefined reference to `sem_post'
./lib/libosip2.a(port_sema.o): In function `osip_sem_wait':
/jiang/workspace/siplib/libosip2-3.6.0/src/osip2/port_sema.c:202: undefined reference to `sem_wait'
./lib/libosip2.a(port_sema.o): In function `osip_sem_trywait':
/jiang/workspace/siplib/libosip2-3.6.0/src/osip2/port_sema.c:211: undefined reference to `sem_trywait'
./lib/libosip2.a(port_thread.o): In function `osip_thread_create':
/jiang/workspace/siplib/libosip2-3.6.0/src/osip2/port_thread.c:55: undefined reference to `pthread_create'
./lib/libosip2.a(port_thread.o): In function `osip_thread_join':
/jiang/workspace/siplib/libosip2-3.6.0/src/osip2/port_thread.c:76: undefined reference to `pthread_join'
collect2: ld returned 1 exit status

再找...看到报错信息里面,pthread_create,线程?果然放入百度,出来答案,立马加入-pthread,支持多线程。

还有一堆报错,再加入-lresolv;

至此,告一段落。















Logo

更多推荐