Question

How to get python pjsua?

$ wget http://www.pjsip.org/release/2.1/pjproject-2.1.tar.bz2
$ tar xvfj pjproject-2.1.tar.bz2
$ cd pjproject-2.1.0
$ ./configure 
$ make dep && make
$ make install
$ ldconfig
$ ldconfig -p | grep pj


$ cd ./pjsip-apps/src/python
$ python setup.py install
running install
running build
running build_py
running build_ext
building '_pjsua' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPJ_AUTOCONF=1 -I-DPJ_IS_BIG_ENDIAN=0 -I-DPJ_IS_LITTLE_ENDIAN=1 -I/home/sun/Downloads/pjproject-2.1.0/pjlib/include -I/home/sun/Downloads/pjproject-2.1.0/pjlib-util/include -I/home/sun/Downloads/pjproject-2.1.0/pjnath/include -I/home/sun/Downloads/pjproject-2.1.0/pjmedia/include -I/home/sun/Downloads/pjproject-2.1.0/pjsip/include -I/usr/include/python2.7 -c _pjsua.c -o build/temp.linux-x86_64-2.7/_pjsua.o
_pjsua.c: In function ‘py_pjsua_enum_transports’:
_pjsua.c:1201:17: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_conf_get_port_info’:
_pjsua.c:2337:9: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_get_snd_dev’:
_pjsua.c:2713:9: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_call_make_call’:
_pjsua.c:3139:7: warning: passing argument 3 of ‘pjsua_call_make_call’ makes pointer from integer without a cast [enabled by default]
In file included from _pjsua.h:27:0,
                 from _pjsua.c:20:
/home/sun/Downloads/pjproject-2.1.0/pjsip/include/pjsua-lib/pjsua.h:4234:22: note: expected ‘const struct pjsua_call_setting *’ but argument is of type ‘unsigned int’
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/_pjsua.o -L/home/sun/Downloads/pjproject-2.1.0/pjlib/lib -L/home/sun/Downloads/pjproject-2.1.0/pjlib-util/lib -L/home/sun/Downloads/pjproject-2.1.0/pjnath/lib -L/home/sun/Downloads/pjproject-2.1.0/pjmedia/lib -L/home/sun/Downloads/pjproject-2.1.0/pjsip/lib -L/home/sun/Downloads/pjproject-2.1.0/third_party/lib -lpjsua-x86_64-unknown-linux-gnu -lpjsip-ua-x86_64-unknown-linux-gnu -lpjsip-simple-x86_64-unknown-linux-gnu -lpjsip-x86_64-unknown-linux-gnu -lpjmedia-codec-x86_64-unknown-linux-gnu -lpjmedia-videodev-x86_64-unknown-linux-gnu -lpjmedia-x86_64-unknown-linux-gnu -lpjmedia-audiodev-x86_64-unknown-linux-gnu -lpjnath-x86_64-unknown-linux-gnu -lpjlib-util-x86_64-unknown-linux-gnu -lresample-x86_64-unknown-linux-gnu -lmilenage-x86_64-unknown-linux-gnu -lsrtp-x86_64-unknown-linux-gnu -lgsmcodec-x86_64-unknown-linux-gnu -lspeex-x86_64-unknown-linux-gnu -lilbccodec-x86_64-unknown-linux-gnu -lg7221codec-x86_64-unknown-linux-gnu -lportaudio-x86_64-unknown-linux-gnu -lpj-x86_64-unknown-linux-gnu -lm -lnsl -lrt -lpthread -lcrypto -lssl -o build/lib.linux-x86_64-2.7/_pjsua.so
/usr/bin/ld: /home/sun/Downloads/pjproject-2.1.0/pjsip/lib/libpjsua-x86_64-unknown-linux-gnu.a(pjsua_acc.o): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/home/sun/Downloads/pjproject-2.1.0/pjsip/lib/libpjsua-x86_64-unknown-linux-gnu.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1


$ python
Python 2.7.3 (default, Apr 10 2013, 05:13:16) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pjsua
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pjsua

EDIT:

p2p | registration | call

$ python sip_hello.py sip:localhost:5080
18:22:21.607 os_core_unix.c !pjlib 2.1 for POSIX initialized
18:22:21.608 sip_endpoint.c  .Creating endpoint instance...
18:22:21.608          pjlib  .select() I/O Queue created (0x131b9f0)
18:22:21.608 sip_endpoint.c  .Module "mod-msg-print" registered
18:22:21.608 sip_transport.  .Transport manager created.
18:22:21.608   pjsua_core.c  .PJSUA state changed: NULL --> CREATED
18:22:21.622   pjsua_core.c  .pjsua version 2.1 for Linux-3.5.0.17/x86_64/glibc-2.15 initialized
18:22:21.625    pjsua_aud.c  ..Error retrieving default audio device parameters: Unable to find default audio device (PJMEDIA_EAUD_NODEFDEV) [status=420006]
Exception: Object: {Account <sip:192.168.1.15:57717>}, operation=make_call(), error=Unable to find default audio device (PJMEDIA_EAUD_NODEFDEV)
Was it helpful?

Solution

setup.py is trying to create shared library build/lib.linux-x86_64-2.7/_pjsua.so by dynamically linking pjsip's libraries, but, those doesn't provide a global offsets table(GOT) (check the link to see why this is needed).

The problem is that ./configure does not provide gcc's -fPIC option, I would suggest creating a configure-linux script like:

#!/bin/sh
#
export CFLAGS="$CFLAGS -fPIC"

./configure

OTHER TIPS

Ok, I can't find a good guide online for this, and @jcm's advice helped me, so I figured I'd just post this here.

I had a similar problem to the OP. During my build I would get the error:

/usr/bin/ld: /opt/pjproject-2.2.1/pjsip/lib/libpjsua-x86_64-unknown-linux-gnu.a(pjsua_acc.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/opt/pjproject-2.2.1/pjsip/lib/libpjsua-x86_64-unknown-linux-gnu.a: could not read symbols: Bad value

Just adding the flag wouldn't fix it.

I don't know how much of this is unncessary, but this is what worked for me. Note that you have to delete the folder and start from scratch. It's possible 'make clean' works, but deleting and re-building was easiest for me:

sudo apt-get install build-essential python-dev
sudo rm -fr pjproject-2.2.1
tar -xf pjproject-2.2.1.tar.bz2 && cd pjproject-2.2.1/
export CFLAGS="$CFLAGS -fPIC"
./configure && make dep && make
cd pjsip-apps/src/python/
sudo python setup.py install

I should also note that I did this in a virtual machine (ubuntu 14.04) because (as far as I can tell) Ubuntu 12.04's compiler has a bug that causes it to segfault:

$ sudo python setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying pjsua.py -> build/lib.linux-x86_64-2.7
running build_ext
building '_pjsua' extension
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPJ_AUTOCONF=1 -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjlib/include -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjlib-util/include -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjnath/include -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjmedia/include -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjsip/include -I/usr/include/python2.7 -c _pjsua.c -o build/temp.linux-x86_64-2.7/_pjsua.o
_pjsua.c: In function ‘py_pjsua_enum_transports’:
_pjsua.c:1202:17: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_conf_get_port_info’:
_pjsua.c:2338:9: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_get_snd_dev’:
_pjsua.c:2714:9: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
In file included from _pjsua.c:20:0:
_pjsua.h: In function ‘PyObj_pjsip_cred_info_delete’:
_pjsua.h:71:13: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.
Preprocessed source stored into /tmp/ccDoI9J3.out file, please attach this to your bugreport.
error: command 'gcc' failed with exit status 1

I am obviously late to the party, but I am answering anyway so it can help someone else. After hours of sweating found these simple steps to install pjsua. These commands also install all the dependancies for you. I used this on UBUNTU, not sure if it works elsewhere. For this to work you need to uninstall and remove any existing pjsua packages.

sudo apt-get install -y software-properties-common # To make add-apt-repository work
sudo add-apt-repository ppa:dennis.guse/sip-tools 
sudo apt-get update 
sudo apt-get install python-pjsua
sudo apt-get install python-pjsua2

To check if everything went well:

python
import pjsua 

Nots sure why the official page doesn't have these commands which can save a lot of time. I got this documentation from here.

To run a sample file:

wget http://svn.pjsip.org/repos/pjproject/trunk/pjsip-apps/src/python/samples/simplecall.py
python simplecall.py sip:ipaddress:portnumber
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top