[capi-sig] Compiling/Linking external Functions (setup.py, distutils, gcc?)

M.-A. Lemburg mal at egenix.com
Wed Nov 19 18:35:49 CET 2008


On 2008-11-19 18:00, Philipp Heuser wrote:
> Hello all,
> 
> I would like to use an existing C-Function from python. Therfore I made
> up an wrapper (wrap.c), where all the variable transformations from
> Python to C are done. That works. Now I would like to call the external
> fuction, which is placed in lets say ext_foo.a with a corresponding
> ext_foo.h  and can be used as a library from plain C.
> 
> I am assuming, that I do have to include the ext_foo.h in my wrap.c with
> #include "ext_foo.h"
> 
> that I have to introduce the function in my C-Code:
> 
> extern int foo(int);
> 
> that I have to tell the setup.py using the distutils stuff where the
> library can be found...
> 
> when compiling a C-Code which is not for python usage I do type
> 
> gcc -o test.o ./test.c ./ext_foo.a -I./foo_h_file_path/
> 
> and everything is fine,
> where within these setup.py files do I have to mention the ./ext_foo.a ?
> When I do place it in the sources-tag, setup procedure complains that it
> doesn't know any .a files... 

The .a file is a library, so you have use the libraries parameter
to have distutils link against this library.

http://docs.python.org/extending/building.html

> if I don't mention it explicitly, just
> giving the include_dirs, compilation works fine, but when importing from
> python 'import wrap' I do get the message: Symbol not found: _foo

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 19 2008)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2008-11-12: Released mxODBC.Connect 0.9.3      http://python.egenix.com/

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611


More information about the capi-sig mailing list