im new to writing makefile. Now im trying to use pjsip c-library, which i installed in my home-directory. I took a little snipped and tried to compile it. Had some errors and so i searched for an solution, so i found out i had to include this library's to the search path. Further there is a possibility to declare them in the makefile, so i tried the 2nd solution.
Here my 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
and here my c-file 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); }
and this is my output of the 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
I also found a useful site which explains how it's done, although i couldn't yet figure it out.
so i found the the simplest solution at this Site, in the section makefile with version 1.6 or later.
# 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
Worked for me, but there was one clue which i stumble over. This is important and is also described at the bottom of the page i linked. If you notice there are spaces towards the bottom of the file (before $(CC) and rm, these are a single tab, not spaces. This is important, or otherwise make command will fail with "missing separator" error.