包括 PJSIP-Library 和编写 makefile
Including PJSIP-Library and writing makefile
我是编写 makefile 的新手。现在我正在尝试使用我安装在我的主目录中的 pjsip c-library。我剪了一小段并尝试编译它。有一些错误,所以我搜索了一个解决方案,所以我发现我必须将这个库包含到搜索路径中。此外,还有可能在 makefile 中声明它们,所以我尝试了第二种解决方案。
这是我的 makefile:
pjpath=home/pi/pjproject-2.4.5
LIB=-L/$(pjpath)/pjlib/lib -L/$(pjpath)/pjlib-util/lib -L/$(pjpath)/pjnath/lib -L/$(pjpath)/pjmedia/lib -L/$(pjpath)/pjsip/lib
INC=-I/$(pjpath)/pjlib/include -I/$(pjpath)/pjlib-util/include -I/$(pjpath)/pjnath/include -I/$(pjpath)/pjmedia/include -I/$(pjpath)/pjsip/include
all:
gcc -o test $(INC) simple_pjsua.c $(LIB) -lpj -lpjlib -lpjnath -lpjmedia -lpjmedia-audiodev -lpjmedia-codec -lpjmedia-videodev -lpjsdp -lpjsip -lpjsip-simple -lpjsip-ua -lpjsua -lpjsua2
clean:
rm simple_pjsua.o test
这是我的 c 文件 simple_pjsua.c:
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#include <pjsua-lib/pjsua.h>
#define THIS_FILE "App"
#define SIP_USER "demo-user2"
#define SIP_DOMAIN "sip:192.168.2.59"
#define SIP_PASSWD "123456"
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata);
static void on_call_state(pjsua_call_id call_id, pjsip_event *e);
static void on_call_media_state(pjsua_call_id call_id);
static void error_exit(const char *title, pj_status_t status);
int main(int argc, char *argv[]){
printf("Hello World");
return 0;
}
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata){
pjsua_call_info ci;
PJ_UNUSED_ARG(acc_id);
PJ_UNUSED_ARG(rdata);
pjsua_call_get_info(call_id, &ci);
PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!", (int) ci.remote_info.slen, ci.remote_info.ptr));
/* Automatically answer incoming calls with 200/OK */
pjsua_call_answer(call_id, 200, NULL, NULL);
}
static void on_call_state(pjsua_call_id call_id, pjsip_event *e){
pjsua_call_info ci;
PJ_UNUSED_ARG(e);
pjsua_call_get_info(call_id, &ci);
PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id, (int) ci.state_text.slen, ci.state_text.ptr));
}
static void on_call_media_state(pjsua_call_id call_id){
pjsua_call_info ci;
pjsua_call_get_info(call_id, &ci);
if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
pjsua_conf_connect(ci.conf_slot, 0);
pjsua_conf_connect(0, ci.conf_slot);
}
}
static void error_exit(const char *title, pj_status_t status){
pjsua_perror(THIS_FILE, title, status);
pjsua_destroy();
exit(1);
}
这是我的 makefile 输出:
gcc -o test -I/home/pi/pjproject-2.4.5/pjlib/include -I/home/pi/pjproject-2.4.5/pjlib-util/include -I/home/pi/pjproject-2.4.5/pjnath/include -I/home/pi/pjproject-2.4.5/pjmedia/include -I/home/pi/pjproject-2.4.5/pjsip/include simple_pjsua.c -L/home/pi/pjproject-2.4.5/pjlib/lib -L/home/pi/pjproject-2.4.5/pjlib-util/lib -L/home/pi/pjproject-2.4.5/pjnath/lib -L/home/pi/pjproject-2.4.5/pjmedia/lib -L/home/pi/pjproject-2.4.5/pjsip/lib -lpj -lpjlib -lpjnath -lpjmedia -lpjmedia-audiodev -lpjmedia-codec -lpjmedia-videodev -lpjsdp -lpjsip -lpjsip-simple -lpjsip-ua -lpjsua -lpjsua2
In file included from /home/pi/pjproject-2.4.5/pjlib/include/pj/config.h:288:0,
from /home/pi/pjproject-2.4.5/pjlib/include/pj/types.h:33,
from /home/pi/pjproject-2.4.5/pjsip/include/pjsip/sip_config.h:27,
from /home/pi/pjproject-2.4.5/pjsip/include/pjsip/sip_types.h:34,
from /home/pi/pjproject-2.4.5/pjsip/include/pjsip.h:24,
from /home/pi/pjproject-2.4.5/pjsip/include/pjsua-lib/pjsua.h:30,
from simple_pjsua.c:3:
/home/pi/pjproject-2.4.5/pjlib/include/pj/config_site.h:3:35: warning: extra tokens at end of #include directive [enabled by default]
/usr/bin/ld: cannot find -lpj
/usr/bin/ld: cannot find -lpjlib
/usr/bin/ld: cannot find -lpjnath
/usr/bin/ld: cannot find -lpjmedia
/usr/bin/ld: cannot find -lpjmedia-audiodev
/usr/bin/ld: cannot find -lpjmedia-codec
/usr/bin/ld: cannot find -lpjmedia-videodev
/usr/bin/ld: cannot find -lpjsdp
/usr/bin/ld: cannot find -lpjsip
/usr/bin/ld: cannot find -lpjsip-simple
/usr/bin/ld: cannot find -lpjsip-ua
/usr/bin/ld: cannot find -lpjsua
/usr/bin/ld: cannot find -lpjsua2
collect2: ld returned 1 exit status
makefile:6: recipe for target 'all' failed
make: *** [all] Error 1
我还找到了一个有用的 site 解释了它是如何完成的,虽然我还没有弄明白。
首先,第一个警告来自库代码,你的代码没有问题。
然后,始终在 所有源文件或目标文件之后指定 link 库 。默认情况下,GNU linker 不会记住尚未引用的库中的符号,因此如果 somelib
尚未被引用,它会简单地删除所有 -lsomelib
通过以前的对象或库。
所以,我敢打赌,这条线
gcc -o test $(INC) simple_pjsua.c $(LIB)
会帮助你(或者至少这个特定的错误会得到解决)。
所以我在 1.6 或更高版本的 makefile 部分找到了最简单的解决方案Site。
# If your application is in a file named myapp.cpp or myapp.c
# this is the line you will need to build the binary.
all: myapp
myapp: myapp.cpp
$(CC) -o $@ $< `pkg-config --cflags --libs libpjproject`
clean:
rm -f myapp.o myop
对我有用,但我偶然发现了一条线索。
这很重要,并且在我链接的页面底部也有描述。如果您注意到文件底部有空格(在 $(CC) 和 rm 之前,这些是单个制表符,而不是空格。这很重要,否则 make 命令将失败并出现“缺少分隔符”错误。
我是编写 makefile 的新手。现在我正在尝试使用我安装在我的主目录中的 pjsip c-library。我剪了一小段并尝试编译它。有一些错误,所以我搜索了一个解决方案,所以我发现我必须将这个库包含到搜索路径中。此外,还有可能在 makefile 中声明它们,所以我尝试了第二种解决方案。
这是我的 makefile:
pjpath=home/pi/pjproject-2.4.5
LIB=-L/$(pjpath)/pjlib/lib -L/$(pjpath)/pjlib-util/lib -L/$(pjpath)/pjnath/lib -L/$(pjpath)/pjmedia/lib -L/$(pjpath)/pjsip/lib
INC=-I/$(pjpath)/pjlib/include -I/$(pjpath)/pjlib-util/include -I/$(pjpath)/pjnath/include -I/$(pjpath)/pjmedia/include -I/$(pjpath)/pjsip/include
all:
gcc -o test $(INC) simple_pjsua.c $(LIB) -lpj -lpjlib -lpjnath -lpjmedia -lpjmedia-audiodev -lpjmedia-codec -lpjmedia-videodev -lpjsdp -lpjsip -lpjsip-simple -lpjsip-ua -lpjsua -lpjsua2
clean:
rm simple_pjsua.o test
这是我的 c 文件 simple_pjsua.c:
#define PJ_IS_LITTLE_ENDIAN 1 #define PJ_IS_BIG_ENDIAN 0 #include <pjsua-lib/pjsua.h> #define THIS_FILE "App" #define SIP_USER "demo-user2" #define SIP_DOMAIN "sip:192.168.2.59" #define SIP_PASSWD "123456" static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata); static void on_call_state(pjsua_call_id call_id, pjsip_event *e); static void on_call_media_state(pjsua_call_id call_id); static void error_exit(const char *title, pj_status_t status); int main(int argc, char *argv[]){ printf("Hello World"); return 0; } static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata){ pjsua_call_info ci; PJ_UNUSED_ARG(acc_id); PJ_UNUSED_ARG(rdata); pjsua_call_get_info(call_id, &ci); PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!", (int) ci.remote_info.slen, ci.remote_info.ptr)); /* Automatically answer incoming calls with 200/OK */ pjsua_call_answer(call_id, 200, NULL, NULL); } static void on_call_state(pjsua_call_id call_id, pjsip_event *e){ pjsua_call_info ci; PJ_UNUSED_ARG(e); pjsua_call_get_info(call_id, &ci); PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id, (int) ci.state_text.slen, ci.state_text.ptr)); } static void on_call_media_state(pjsua_call_id call_id){ pjsua_call_info ci; pjsua_call_get_info(call_id, &ci); if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) { pjsua_conf_connect(ci.conf_slot, 0); pjsua_conf_connect(0, ci.conf_slot); } } static void error_exit(const char *title, pj_status_t status){ pjsua_perror(THIS_FILE, title, status); pjsua_destroy(); exit(1); }
这是我的 makefile 输出:
gcc -o test -I/home/pi/pjproject-2.4.5/pjlib/include -I/home/pi/pjproject-2.4.5/pjlib-util/include -I/home/pi/pjproject-2.4.5/pjnath/include -I/home/pi/pjproject-2.4.5/pjmedia/include -I/home/pi/pjproject-2.4.5/pjsip/include simple_pjsua.c -L/home/pi/pjproject-2.4.5/pjlib/lib -L/home/pi/pjproject-2.4.5/pjlib-util/lib -L/home/pi/pjproject-2.4.5/pjnath/lib -L/home/pi/pjproject-2.4.5/pjmedia/lib -L/home/pi/pjproject-2.4.5/pjsip/lib -lpj -lpjlib -lpjnath -lpjmedia -lpjmedia-audiodev -lpjmedia-codec -lpjmedia-videodev -lpjsdp -lpjsip -lpjsip-simple -lpjsip-ua -lpjsua -lpjsua2
In file included from /home/pi/pjproject-2.4.5/pjlib/include/pj/config.h:288:0,
from /home/pi/pjproject-2.4.5/pjlib/include/pj/types.h:33,
from /home/pi/pjproject-2.4.5/pjsip/include/pjsip/sip_config.h:27,
from /home/pi/pjproject-2.4.5/pjsip/include/pjsip/sip_types.h:34,
from /home/pi/pjproject-2.4.5/pjsip/include/pjsip.h:24,
from /home/pi/pjproject-2.4.5/pjsip/include/pjsua-lib/pjsua.h:30,
from simple_pjsua.c:3:
/home/pi/pjproject-2.4.5/pjlib/include/pj/config_site.h:3:35: warning: extra tokens at end of #include directive [enabled by default]
/usr/bin/ld: cannot find -lpj
/usr/bin/ld: cannot find -lpjlib
/usr/bin/ld: cannot find -lpjnath
/usr/bin/ld: cannot find -lpjmedia
/usr/bin/ld: cannot find -lpjmedia-audiodev
/usr/bin/ld: cannot find -lpjmedia-codec
/usr/bin/ld: cannot find -lpjmedia-videodev
/usr/bin/ld: cannot find -lpjsdp
/usr/bin/ld: cannot find -lpjsip
/usr/bin/ld: cannot find -lpjsip-simple
/usr/bin/ld: cannot find -lpjsip-ua
/usr/bin/ld: cannot find -lpjsua
/usr/bin/ld: cannot find -lpjsua2
collect2: ld returned 1 exit status
makefile:6: recipe for target 'all' failed
make: *** [all] Error 1
我还找到了一个有用的 site 解释了它是如何完成的,虽然我还没有弄明白。
首先,第一个警告来自库代码,你的代码没有问题。
然后,始终在 所有源文件或目标文件之后指定 link 库 。默认情况下,GNU linker 不会记住尚未引用的库中的符号,因此如果 somelib
尚未被引用,它会简单地删除所有 -lsomelib
通过以前的对象或库。
所以,我敢打赌,这条线
gcc -o test $(INC) simple_pjsua.c $(LIB)
会帮助你(或者至少这个特定的错误会得到解决)。
所以我在 1.6 或更高版本的 makefile 部分找到了最简单的解决方案Site。
# If your application is in a file named myapp.cpp or myapp.c
# this is the line you will need to build the binary.
all: myapp
myapp: myapp.cpp
$(CC) -o $@ $< `pkg-config --cflags --libs libpjproject`
clean:
rm -f myapp.o myop
对我有用,但我偶然发现了一条线索。 这很重要,并且在我链接的页面底部也有描述。如果您注意到文件底部有空格(在 $(CC) 和 rm 之前,这些是单个制表符,而不是空格。这很重要,否则 make 命令将失败并出现“缺少分隔符”错误。