Python's easy_install and custom header/librar

2020-08-01 04:08发布

问题:

I am trying to install adns-python using linux and had to recompile adns with some special options, so I can't seem to use easy_install <tarball> as I normally would

(py26_default)[mpenning@localhost src]$ easy_install adns-python-1.2.1.tar.gz
Processing adns-python-1.2.1.tar.gz
Running adns-python-1.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-9cVl4i/adns-python-1.2.1/egg-dist-tmp-vvO8Ms
adnsmodule.c:10:18: error: adns.h: No such file or directory
adnsmodule.c:31: error: expected specifier-qualifier-list before âadns_stateâ

adns.h is installed under /opt/adns/include/adns.h; how can I make easy_install install with a local installation of adns?

EDIT

After the attempt below, I still find an ld error, even though I exported LD_LIBRARY_PATH...

(py26_default)[mpenning@localhost src]$ ls /opt/adns/lib/
libadns.a  libadns.so  libadns.so.1  libadns.so.1.2
(py26_default)[mpenning@localhost src]$ export LD_LIBRARY_PATH=/opt/adns/lib
(py26_default)[mpenning@localhost src]$ C_INCLUDE_PATH=/opt/adns/include easy_install ./adns-python-1.2.1.tar.gz
Processing adns-python-1.2.1.tar.gz
Running adns-python-1.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-x68T9f/adns-python-1.2.1/egg-dist-tmp-MpCzMP
/usr/bin/ld: cannot find -ladns
collect2: ld returned 1 exit status
error: Setup script exited with error: command 'gcc' failed with exit status 1
(py26_default)[mpenning@localhost src]$ 

回答1:

LD_LIBRARY_PATH is used to find a shared library at runtime (when an executable is run), not during linking.

To build the extension, unpack the tarball and run:

python setup.py build_ext -I/opt/adns/include -L/opt/adns/lib -R/opt/adns/lib

To install:

python setup.py install

You could specify build_ext options in setup.cfg:

[build_ext]
include_dirs=/opt/adns/include
library_dirs=/opt/adns/lib
rpath=/opt/adns/lib

in this case you could run easy_install directly.



回答2:

Please try like this

INCLUDE_PATH=/opt/adns/include easy_install adns-python-1.2.1.tar.gz

if it is not working please try with CPLUS_INCLUDE_PATH or C_INCLUDE_PATH