为Windows 7编译IP2Location Python扩展

时间:2009-11-29 14:36:59

标签: python c windows

我想编译/安装这里找到的IP2Location Python扩展:

  

www.ip2location.com/python.aspx

我尝试按照这些网站上的说明进行操作:

  

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

但我没有在哪里。问题是Python扩展依赖于另一个C库:

  

www.ip2location.com/c.aspx

当我尝试在cygwin中编译这个库时,我得到以下输出:

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

我在Windows 7 32位上运行python 2.6.3。 我有MS Visual Studio 2008(虽然不知道如何使用它),当然还有cygwin / MinGW。

非常感谢任何帮助或指示。

2 个答案:

答案 0 :(得分:2)

好的,完整的解决方案是:

  1. 下载stdint.h并将其放入IP2Location C Library文件夹:http://msinttypes.googlecode.com/svn/trunk/stdint.h
  2. 打开dos提示符并执行“C:\ Program Files \ Microsoft Visual Studio 9.0 \ VC \ vcvarsall.bat”
  3. 从同一个dos提示符执行“nmake / f Makefile.win”
  4. cd到Python扩展文件夹并执行“set LINK = / nod:msvcrt.lib”
  5. 最后做标准的“python setup.py install”
  6. “set LINK = / nod:msvcrt.lib”的建议归功于Providenza的Tim Roberts& Boekelheide,Inc(probo.com)。 - 他非常友好地回答我在python win32邮件列表上的求助。谢谢蒂姆!

答案 1 :(得分:1)

尝试将-lws2_32选项添加到链接命令。

顺便说一句,还有另一个pure Python library从IP获得国家。