problem in compiling the module in VC2010

2011-07-20 Thread llwaeva
Hi all,
  I am compiling the example with MCVS2010

#include "Python.h"

static PyObject *
ex_foo(PyObject *self, PyObject *args)
{
printf("Hello, world\n");
Py_INCREF(Py_None);
return Py_None;
}

static PyMethodDef example_methods[] = {
{"foo", ex_foo, METH_VARARGS, "foo() doc string"},
{NULL, NULL}
};

static struct PyModuleDef examplemodule = {
PyModuleDef_HEAD_INIT,
"example",
"example module doc string",
-1,
example_methods,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC
PyInit_example(void)
{
return PyModule_Create(&examplemodule);
}


But it reports the following message:

error LNK2001: unresolved external symbol __imp___Py_NoneStruct
error LNK2019: unresolved external symbol __imp__PyModule_Create2
referenced in function _PyInit_example

My os is windows 7 64-bit. Compiler: VC2010



-- 
http://mail.python.org/mailman/listinfo/python-list


problem in compiling C API in mingw

2011-07-26 Thread llwaeva

Hi all again, 
  I wonder if so far only Python 2.5.x support c extension. I try the
MSVC 2010 and 2008, also try mingw (gcc 4.x.x) and swig. But even I try
the simplest example, it said 

example_wrap.o:example_wrap.c:(.text+0x10ac): undefined reference to 
`_imp__PyObject_Free'
example_wrap.o:example_wrap.c:(.text+0x10f5): undefined reference to 
`_imp__PyCapsule_Import'
example_wrap.o:example_wrap.c:(.text+0x1100): undefined reference to 
`_imp__PyErr_Occurred'
example_wrap.o:example_wrap.c:(.text+0x110e): undefined reference to 
`_imp__PyErr_Clear'
example_wrap.o:example_wrap.c:(.text+0x1125): undefined reference to 
`_imp__PyImport_AddModule'
example_wrap.o:example_wrap.c:(.text+0x1144): undefined reference to 
`_imp__PyCapsule_New'
example_wrap.o:example_wrap.c:(.text+0x1165): undefined reference to 
`_imp__PyModule_AddObject'
example_wrap.o:example_wrap.c:(.text+0x1170): undefined reference to 
`_imp__PyBaseObject_Type'
example_wrap.o:example_wrap.c:(.text+0x11b2): undefined reference to 
`_imp__PyObject_SetAttr'
example_wrap.o:example_wrap.c:(.rdata+0x1e8): undefined reference to 
`PyObject_GenericGetAttr'
collect2: ld returned 1 exit status

and some sort like that.

So I try to use the compiler itself and get rid of all 3rd part tool,
here is what I did

/ source code
#include "Python.h"

static  PyObject *
ex_foo(PyObject *self, PyObject *args)
{
printf("Hello, world n " );
Py_INCREF(Py_None);
return  Py_None;
}

static  PyMethodDef example_methods[] = {
{"foo" , ex_foo, METH_VARARGS, "foo() doc string" },
{NULL , NULL }
};

static  struct  PyModuleDef examplemodule = {
PyModuleDef_HEAD_INIT,
"example" ,
"example module doc string" ,
-1 ,
example_methods,
NULL ,
NULL ,
NULL ,
NULL
};

PyMODINIT_FUNC
PyInit_example(void )
{
return  PyModule_Create(&examplemodule);
}

/// my setup.py
from distutils.core import setup, Extension

module1 = Extension('example', sources = ['example.c'])

setup (name = 'example', version = '1.0', description = 'This is a demo 
package', ext_modules = [module1])


// running
python setup.py build --compiler=mingw32


$ python setup.py build --compiler=mingw32
running build
running build_ext
building 'example' extension
D:\Programs\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ic:\Program Files (x8
6)\Python\include" "-Ic:\Program Files (x86)\Python\PC" -c example.c -o build\te
mp.win-amd64-3.1\Release\example.o
writing build\temp.win-amd64-3.1\Release\example.def
D:\Programs\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win-amd64-3.1\Re
lease\example.o build\temp.win-amd64-3.1\Release\example.def "-Lc:\Program Files
 (x86)\Python\libs" "-Lc:\Program Files (x86)\Python\PCbuild\amd64" -lpython31 -
lmsvcr90 -o build\lib.win-amd64-3.1\example.pyd
build\temp.win-amd64-3.1\Release\example.o:example.c:(.text+0x13): undefined ref
erence to `_imp___Py_NoneStruct'
build\temp.win-amd64-3.1\Release\example.o:example.c:(.text+0x32): undefined ref
erence to `_imp__PyModule_Create2'
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
- Original Message Ends 



-- 
http://mail.python.org/mailman/listinfo/python-list


seeking an example on C extension works in python 3.1.x or above

2011-07-26 Thread llwaeva
Hello,
  I have been searching the example on C extension that works in python
3.1.x ror above for long time. I tried the simple example given in
python document or enclosed in python's src (PC folder), doesn't work,

undefined reference to  `_imp___Py_NoneStruct'

and
undefined reference to  `_imp__PyModule_Create2'

error caught. For the first one, somewhere it could be fixed by some way
mentioned in the faq somewhere. But I don't see any suggestion in the
internet or in the mail list about that. Can any one who ever succeed to  
compile
the any example to extend python (3.1 +) with C API under windows?

I am using windows 64bit + VC2010 and gcc  mingw.
-- 
http://mail.python.org/mailman/listinfo/python-list