Morning,

I'm attempting to make a c++ api wrapper to an existing library. I'm  
having some trouble getting past the basics. My first stop was the  
manual, but I could not get the Rectangle Demo to compile on my  
system. Some searching of the mailing list found a thread where  
someone was kind enough to post corrections to the wiki and manual  
entries (http://codespeak.net/pipermail/cython-dev/2008-April/000516.html 
).

With this I was able to get the example to compile, but quickly ran  
into issues of my own when trying to duplicate it for my library.

The library is installed into /opt/local with headers in /opt/local/ 
include/mp4v2 and libs in /opt/local/lib. I was going to first attempt  
to duplicate the examples provided by the project. The first step  
would be to declare a MP4FileHandle object and open it with  
MP4Modify(). It would look something like this:

> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
> #include <mp4v2/mp4v2.h>
>
> int main (int argc, char const **argv)
> {
>   MP4FileHandle file = MP4Modify(argv[1], MP4_DETAILS_ERROR, 0);
>   if(file == MP4_INVALID_FILE_HANDLE) {
>     printf("MP4Modify failed\n");
>     return 1;
>   }
>
>   MP4Close(file);
>
>   return 0;
> }

Obviously, the MP4* definitions are found in mp4v2/mp4v2.h. Compiling  
is also straight forward:

> g++ -I/opt/local/include -L/opt/local/lib -lmp4v2 main.cpp

Now, on to duplicating or declaring these in a cython interface file.

I put together a setup.py like so:

> from distutils.core import setup
> from distutils.extension import Extension
> from Cython.Distutils import build_ext
>
> utils = Extension(
>     "utils",
>     sources=["pymp4v2/utils.pyx"],
>     include_dirs=["/opt/lcoal/include/"],
>     libraries=["mp4v2"],
>     library_dirs=['/opt/local/lib'],
>     language="c++",
>     define_macros=[('MACOSX_DEPLOYMENT_TARGET', 10.5)],
> )
>
> setup(
>     ext_modules = [utils],
>     cmdclass={'build_ext':build_ext},
>
>
> )

I then created the following pyx file and attempted build. I tried  
various other combos e.g. cdef extern from "mp4v2.mp4v2.h" or "mp4v2/ 
mp4v2.h".

any guidance is greatly appreciated. I'm sure I'm missing some section  
of the documentation that explains this, my apologies if that's the  
case.

-james

> """
> Python Wrapper Interface for libmp4v2 methods.
> """
> cdef extern from "mp4v2.h":
>     void* MP4FileHandle
>     MP4FileHandle MP4Modify(char* fileName, int verbosity=0, int  
> flags = 0)

> running build_ext
> cythoning pymp4v2/utils.pyx to pymp4v2/utils.cpp
>
> Error converting Pyrex file to C:
> ------------------------------------------------------------
> ...
> """
> Python Wrapper Interface for libmp4v2 methods.
> """
> cdef extern from "mp4v2.h":
>     void* MP4FileHandle
>     MP4FileHandle MP4Modify(char* fileName, int verbosity=0, int  
> flags = 0)   ^
> ------------------------------------------------------------
>
> /Users/jkyle/Projects/pymp4v2.env/src/python/pymp4v2/utils.pyx:6:4:  
> 'MP4FileHandle' is not a type identifier
> building 'utils' extension
> /usr/bin/gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG - 
> g -fwrapv -O3 -Wall -Wstrict-prototypes - 
> DMACOSX_DEPLOYMENT_TARGET=10.5 -I/opt/lcoal/include/ -I/opt/local/ 
> Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 - 
> c pymp4v2/utils.cpp -o build/temp.macosx-10.3-i386-2.6/pymp4v2/utils.o
> cc1plus: warning: command line option "-Wstrict-prototypes" is valid  
> for C/ObjC but not for C++
> pymp4v2/utils.cpp:1:2: error: #error Do not use this file, it is the  
> result of a failed Cython compilation.
> error: command '/usr/bin/gcc-4.0' failed with exit status 1
>
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to