[C++-sig] [Py++] Generate Python code for ctypes?

Nikolaus Rath Nikolaus at rath.org
Sun Dec 13 19:24:21 CET 2009


Roman Yakovenko <roman.yakovenko at gmail.com> writes:
> On Sun, Dec 13, 2009 at 4:54 AM, Nikolaus Rath <Nikolaus at rath.org> wrote:
>> Roman Yakovenko <roman.yakovenko at gmail.com> writes:
>>> You can take a look on gmplib example:
>>> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/examples/gmplib_dev/
>>> It is fully working.
>>
>> Do I need the CVS version?
>
> Yes. The version, which contains ctypes code generator, was not released yet.

Alright, now it seems to work great already! But I have another question
right away:

The generated code contains

libfuse_lib = ctypes.CDLL( r"/usr/lib/libfuse.so" )

I'd rather have the library looked up dynamically, as in

libfuse = CDLL(find_library("fuse"))

but it seems that I have to hardcode the complete path in
project_env.py, otherwise I get:

Traceback (most recent call last):
  File "generate_code.py", line 15, in <module>
    mb = ctypes_module_builder_t( [project_env.gmp.header_file], project_env.gmp.symbols_file, gccxml_cfg )
  File "/home/nikratio/.local/lib/python2.6/site-packages/pyplusplus/module_builder/ctypes_builder.py", line 42, in __init__
    self.__blob2decl = binary_parsers.merge_information( self.global_ns, exported_symbols_file )
  File "/home/nikratio/.local/lib/python2.6/site-packages/pygccxml/binary_parsers/parsers.py", line 303, in merge_information
    symbols = parser.parse()
  File "/home/nikratio/.local/lib/python2.6/site-packages/pygccxml/binary_parsers/parsers.py", line 95, in parse
    self.__loaded_symbols = self.load_symbols()
  File "/home/nikratio/.local/lib/python2.6/site-packages/pygccxml/binary_parsers/parsers.py", line 256, in load_symbols
    mangled_smbls = self.__extract_symbols( [part % tmpl_args for part in self.cmd_mangled] )
  File "/home/nikratio/.local/lib/python2.6/site-packages/pygccxml/binary_parsers/parsers.py", line 246, in __extract_symbols
    output = self.__execute_nm( cmd )
  File "/home/nikratio/.local/lib/python2.6/site-packages/pygccxml/binary_parsers/parsers.py", line 242, in __execute_nm
    raise RuntimeError( os.linesep.join(msg) )
RuntimeError: Unable to extract public\exported symbols from 'libfuse.so.2' file.
The command line, which was used to extract symbols, is "['nm', '--extern-only', '--dynamic', '--defined-only', '--numeric-sort', 'libfuse.so.2']"

Is there a way to accomplish this?


Best,

   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C



More information about the Cplusplus-sig mailing list