OpenWrt Forum Archive

Topic: Compiling python modules

The content of this topic has been archived on 25 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi there! while i just registered in this forum, i have read it for a long time.

So I'm writing a python application to manage interfaces on the go putting the on mode monitor. My goal is to make it run either on PC and openwrt devices.

The problem comes when I try to install a python module called netifaces, which is very helpful managing interfaces info. Although the code is wide compatible with Linux devices, it can't be installed with easy_install on the router itself, as you may see in the output.:

here is the code:
http://alastairs-place.net/projects/net … 0.8.tar.gz

root@myroutex:/tmp# easy_install netifaces/
Processing
Running setup.py -q bdist_egg --dist-dir /tmp/netifaces/egg-dist-tmp-Bm2DH5
checking for getifaddrs... not found. (cached)
checking for getnameinfo... not found. (cached)
checking for socket IOCTLs... not found. (cached)
checking for optional header files... none found. (cached)
checking whether struct sockaddr has a length field... no. (cached)
checking which sockaddr_xxx structs are defined... none! (cached)
unable to execute mips-openwrt-linux-uclibc-gcc: No such file or directory
error: Setup script exited with error: command 'mips-openwrt-linux-uclibc-gcc' failed with exit status 1

in a common pc just running

python setup.py build

builds a .so file and

python setup.py install

does all the job.

I don't know if it is posible to cross compile it, because the installer itself is contained in the module, setup.py

Is there any way to install it in openwrt? Any hint about it?


Thanks folks, and sorry for my rough english sad

(Last edited by peluzza on 28 Nov 2013, 23:16)

Hi Peluzza,

It has been some time since your post, hopefully you haven't lost interest in this. I have attempted this sucessfully using netifaces-0.10.2 and OpenWRT 12.09 attitude adjustment.

I'm trying to achieve the same thing as you, that is build the netifaces for openwrt. My approach is to cross compile it roughly following the guide on this blog: http://whatschrisdoing.com/blog/2009/10 … xtensions/

I'm doing this on my host machine, which is running 64 bit Ubuntu 12.04 LTS, for my target, Atom based PC (i486) - so I'm just using the generic x86 openwrt target (see http://www.stumbleupon.com/su/19OLDp for details about my target device)

1. Built an openwrt image from source (checked out the latest svn revision for attitude adjustment) - when building from source ensure that you have the openwrt packages "python" and "distribute" set as built in to your image

2. On my host machine I had to install some additional packages for cross compiling with python
sudo apt-get install python-setuptools
sudo easy_install distribute (potentially not required or installed as a prerequisite to distutilscross)
sudo easy_install distutilscross

3. Setup some environmental variables to point to the compile, libraries and headers of openwrt
export STAGING_DIR=/home/allsey87/Desktop/OpenWRT-x86/attitude_adjustment/staging_dir
export PYTHONXCPREFIX=${STAGING_DIR}/target-i386_uClibc-0.9.33.2/usr
export CROSS_COMPILE=${STAGING_DIR}/toolchain-i386_gcc-4.6-linaro_uClibc-0.9.33.2/bin/i486-openwrt-linux-uclibc-
export CC="${CROSS_COMPILE}gcc -pthread"
export LDSHARED="${CC} -shared"
export LDFLAGS="-L${STAGING_DIR}/target-i386_uClibc-0.9.33.2/lib -L${STAGING_DIR}/target-i386_uClibc-0.9.33.2/usr/lib"

4. Then I ran the following command to build the egg
python setup.py build -x bdist_egg --plat-name=linux-x86

5. Copied the outputted egg into /tmp on my openwrt box and ran easy_install netifaces-0.10.2-py2.7-linux-x86.egg

6. Starting up the python interpreter running the following commands gave me the following output

#python
>>> import netifaces
>>> netifaces.interfaces()
['lo', 'eth0', 'br-lan']

Let me know if this helps!

Dear All,

I have tried the same procedure on MIPSEL but failed.

mt7688sdk/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-uclibc-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -I/mt7688sdk/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/include -fPIC -DNETIFACES_VERSION=0.10.4 -DHAVE_GETIFADDRS=1 -DHAVE_GETNAMEINFO=1 -DHAVE_NETAX25_AX25_H=1 -DHAVE_NETECONET_EC_H=1 -DHAVE_NETIPX_IPX_H=1 -DHAVE_NETPACKET_PACKET_H=1 -DHAVE_LINUX_IRDA_H=1 -DHAVE_LINUX_ATM_H=1 -DHAVE_LINUX_LLC_H=1 -DHAVE_LINUX_TIPC_H=1 -DHAVE_LINUX_DN_H=1 -DHAVE_SOCKADDR_AX25=1 -DHAVE_SOCKADDR_IN=1 -DHAVE_SOCKADDR_IN6=1 -DHAVE_SOCKADDR_IPX=1 -DHAVE_SOCKADDR_UN=1 -DHAVE_SOCKADDR_EC=1 -DHAVE_SOCKADDR_LL=1 -DHAVE_SOCKADDR_ATMPVC=1 -DHAVE_SOCKADDR_ATMSVC=1 -DHAVE_SOCKADDR_DN=1 -DHAVE_SOCKADDR_IRDA=1 -DHAVE_SOCKADDR_LLC=1 -DHAVE_PF_NETLINK=1 -I/usr/include/python2.7 -c netifaces.c -o build/temp.linux-x86_64-2.7/netifaces.o
In file included from /usr/include/python2.7/Python.h:8:0,
                 from netifaces.c:1:
/usr/include/python2.7/pyconfig.h:65:5: error: #error unknown multiarch location for pyconfig.h
#   error unknown multiarch location for pyconfig.h
     ^
In file included from /usr/include/python2.7/pyport.h:4:0,
                 from /usr/include/python2.7/Python.h:58,
                 from netifaces.c:1:
/usr/include/python2.7/pyconfig.h:65:5: error: #error unknown multiarch location for pyconfig.h
#   error unknown multiarch location for pyconfig.h
     ^
In file included from /usr/include/python2.7/pymath.h:4:0,
                 from /usr/include/python2.7/Python.h:77,
                 from netifaces.c:1:
/usr/include/python2.7/pyconfig.h:65:5: error: #error unknown multiarch location for pyconfig.h
#   error unknown multiarch location for pyconfig.h
     ^
netifaces.c: In function 'gateways':
netifaces.c:1472:3: warning: implicit declaration of function 'getpagesize' [-Wimplicit-function-declaration]
   int pagesize = getpagesize();
   ^
netifaces.c:1510:5: warning: implicit declaration of function 'close' [-Wimplicit-function-declaration]
     close (s);
     ^
netifaces.c:1609:11: error: 'errno' undeclared (first use in this function)
           errno = -perr->error;


It seems build_egg keep looking my host Python path for the header files.
I tried to change the setup.cfg to add "include_dirs" but it doesn't work also.

Any advice?

The discussion might have continued from here.