views:

168

answers:

2

I want to compile / install the IP2Location Python extension found here:

www.ip2location.com/python.aspx

I tried following the instructions at these sites:

eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/ boodebr.org/main/python/build-windows-extensions

But I am getting no where. The problem is the Python extension relies on another C library:

www.ip2location.com/c.aspx

When I try to compile this library in cygwin I get the following output:

make  all-recursive
make[1]: Entering directory `/home/ty/Python-IP2Location/C-IP2Location-3.0.0'
Making all in libIP2Location
make[2]: Entering directory `/home/ty/Python-IP2Location/C-IP2Location-3.0.0/li
bIP2Location'
/bin/sh ../libtool --tag=CC   --mode=link gcc -mno-cygwin -IiMath/ -g -O2 -modul
e -no-undefined -avoid-version  -o libIP2Location.la -rpath /cygdrive/c/MinGW/li
b libIP2Location_la-IP2Location.lo libIP2Location_la-imath.lo
libtool: link: rm -fr  .libs/libIP2Location.dll.a
libtool: link: gcc -mno-cygwin -shared  .libs/libIP2Location_la-IP2Location.o .l
ibs/libIP2Location_la-imath.o    -mno-cygwin   -o .libs/libIP2Location.dll -Wl,-
-enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libIP2Location.dll.
a
.libs/libIP2Location_la-IP2Location.o: In function `IP2Location_ip2no':
/home/ty/Python-IP2Location/C-IP2Location-3.0.0/libIP2Location/IP2Location.c:71
8: undefined reference to `_inet_addr@4'
Creating library file: .libs/libIP2Location.dll.a
collect2: ld returned 1 exit status
make[2]: *** [libIP2Location.la] Error 1
make[2]: Leaving directory `/home/ty/Python-IP2Location/C-IP2Location-3.0.0/lib
IP2Location'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ty/Python-IP2Location/C-IP2Location-3.0.0'
make: *** [all] Error 2

I'm running python 2.6.3 on Windows 7 32-bit. I have MS Visual Studio 2008 (though no idea how to use it) and of course cygwin / MinGW.

Any help or pointers would be greatly appreciated.

+1  A: 

Try adding -lws2_32 option to linking command.

BTW, there is another pure Python library to get country from IP.

Denis Otkidach
Thanks for the reply - unfortunately it didn't help.The python lib you mentioned is not quite as full featured as the IP2Location package, but thanks for the tip. Also, I've already written a pure python library but it is not very quick - I am hoping the C extension will speed things up for me.
jckdnk111
Did linking with ws2_32.lib help to resolve undefined reference issue? This is a windows (I'm not sure about windows 7 though) library where this symbols defined.
Denis Otkidach
No, it didn't make any difference. Thanks for your help though.
jckdnk111
+1  A: 

OK, so the full solution is:

  1. download stdint.h and put it in the IP2Location C Library folder: http://msinttypes.googlecode.com/svn/trunk/stdint.h
  2. open a dos prompt and execute "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
  3. from the same dos prompt execute "nmake /f Makefile.win"
  4. cd to the Python extension folder and execute "set LINK=/nod:msvcrt.lib"
  5. lastly do the standard "python setup.py install"

The credit for the "set LINK=/nod:msvcrt.lib" advice goes to Tim Roberts of Providenza & Boekelheide, Inc (probo.com). -- he was kind enough to answer my cry for help on the python win32 mailing list. Thanks Tim!

jckdnk111