> Use distutils to compile Pyrex extensions. Use Soya's setup.py as an
> example. Also, it should be cimport _soya, without the .pxd at the
> end.
> 
> The .c file will contain the C code for all the declarations that are
> in the .pxd file. Where else would you expect the module to get its
> hands on them? It can't magically extract them from _soya.so at
> runtime. This includes all the class definitions, but not the actual
> method code.  Think of it as including the .h file in your code
> instead of including it separately.
> 
> One of these days I want to write a compiler for real Python code, but
> that's probably a ways off, as I know absolutely nothing about type
> snarfing. It'd be based on compiler.py.
> 

ok here is my test.pyx:

------------------------------------------- cimport _soya

cdef class Test(_soya.CoordSyst): pass

-------------------------------------------

and here is my setup.py. i trimmed off what i think i dont need and also
found a class that let me pass include directories to pyrex

-------------------------------------------
#! /usr/bin/env python

INCDIR = [
  "/usr/include",
  "/usr/local/include",
  "/usr/X11R6/include",
  "/usr/include/freetype2",
  "/usr/local/include/freetype2",
  "/usr/include/cal3d",
  "/usr/local/include/cal3d",
  "/sw/include", # For Mac OS X
  "../"
  ]
LIBDIR = [
  "/usr/lib",
  "/usr/local/lib",
  "/usr/X11R6/lib",
  "/sw/lib/", # For Mac OS X
  ]

import os.path, sys, glob, distutils.core, distutils.sysconfig
from distutils.core import setup, Extension

HERE = os.path.dirname(sys.argv[0])

endian = sys.byteorder
if endian == "big":
  DEFINES = [("SOYA_BIG_ENDIAN", endian)]
else:
  DEFINES = []

#from config import *

if sys.platform[:3] == "win":
  LIBS = ["m", "opengl32", "glu32", "SDL", "freetype", "cal3d", "stdc++"]
else:
  LIBS = ["m", "GL", "GLU", "SDL", "freetype", "cal3d", "stdc++"]

SOYA_PYREX_SOURCES  = ["test.pyx"]
SOYA_C_SOURCES      = ["test.c"]

import distutils.command.build_ext
import Pyrex.Compiler.Main

from Pyrex.Compiler.Errors import PyrexError
from distutils.dep_util import newer
import os
import sys

def replace_suffix(path, new_suffix):
    return os.path.splitext(path)[0] + new_suffix

class build_ext(distutils.command.build_ext.build_ext):

  description = ("compile Pyrex scripts, then build C/C++ extensions "
                 "(compile/link to build directory)")

  def finalize_options(self):
      distutils.command.build_ext.build_ext.finalize_options(self)

  def swig_sources(self, sources):
      if not self.extensions:
          return
      
      pyx_sources = [source for source in sources
                     if source.endswith('.pyx')]
      other_sources = [source for source in sources
                       if not source.endswith('.pyx')]
      c_sources = []

      for pyx in pyx_sources:
          # should I raise an exception if it doesn't exist?
          if os.path.exists(pyx):
              source = pyx
              target = replace_suffix(source, '.c')
              c_sources.append(target)
              if newer(source, target) or self.force:
                  self.pyrex_compile(source)
      return c_sources + other_sources

  def pyrex_compile(self, source):
      options = Pyrex.Compiler.Main.CompilationOptions(
          show_version=0,
          use_listing_file=0,
          errors_to_stderr=1,
          include_path=self.get_pxd_include_paths(),
          c_only=1,
          obj_only=1,
          output_file=None)
      
      result = Pyrex.Compiler.Main.compile(source, options)
      if result.num_errors <> 0:
          sys.exit(1)

  def get_pxd_include_paths(self):
      """Override this to return a list of include paths for pyrex.
      """
      return ["../soya"]


KARGS = {
  "ext_modules" : [
  Extension("test", SOYA_PYREX_SOURCES,
            include_dirs=INCDIR, library_dirs=LIBDIR,
            libraries=LIBS, define_macros=DEFINES,
            extra_compile_args = ["-w"], # with GCC ; disable (Pyrex-dependant) 
warning
            ),
  ],
  "cmdclass" : {
      'build_ext'   : build_ext,            # Pyrex magic stuff
      },
  }

setup(
  **KARGS)

----------------------------------

but running it gives me:

running buildded from test.c:16:
running build_extd/cal3d_wrapper.h:366: error: parse error before "bool"
building 'test' extension.h:72: error: storage size of `operator' isn't known
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes 
-fPIC -I/usr/include -I/usr/local/include -I/usr/X11R6/include 
-I/usr/include/freetype2 -I/usr/local/include/freetype2 -I/usr/include/cal3d 
-I/usr/local/include/cal3d -I/sw/include -I../ -I/usr/include/python2.3 -c 
test.c -o build/temp.linux-i686-2.3/test.o -w
In file included from /usr/include/cal3d/global.h:24,
                 from /usr/include/cal3d/matrix.h:18,
                 from test.c:15:
/usr/include/cal3d/platform.h:82:20: iostream: No such file or directory
/usr/include/cal3d/platform.h:83:19: fstream: No such file or directory
/usr/include/cal3d/platform.h:84:19: sstream: No such file or directory
/usr/include/cal3d/platform.h:85:18: string: No such file or directory
/usr/include/cal3d/platform.h:86:18: vector: No such file or directory
/usr/include/cal3d/platform.h:87:16: list: No such file or directory
/usr/include/cal3d/platform.h:88:15: map: No such file or directory
In file included from /usr/include/cal3d/global.h:24,
                 from /usr/include/cal3d/matrix.h:18,
                 from test.c:15:
/usr/include/cal3d/platform.h:98: error: parse error before "CalPlatform"
/usr/include/cal3d/platform.h:99: error: syntax error before '{' token
/usr/include/cal3d/platform.h:108: error: parse error before "readFloat"
/usr/include/cal3d/platform.h:108: error: parse error before ':' token
/usr/include/cal3d/platform.h:109: error: parse error before "readInteger"
/usr/include/cal3d/platform.h:109: error: parse error before ':' token
/usr/include/cal3d/platform.h:110: error: parse error before "readString"
....
...
..


im slightly confused. my c compiling skills are not good :)

dunk






Reply via email to