3

using Anaconda, Python 3.4 and Win7 64bit, i can't get this running:

C Code:

    int addInts(int a, int b)
{
    return a+b;
}

PYX file:

cdef extern from "square.cpp":
    int addInts(int, int)

def pAddInts(int a, int b):
    return addInts(a, b)

and testfile:

res = callCpp.pAddInts(3, 4)

error message:

Traceback (most recent call last):
  File "testScript.py", line 9, in <module>
    res = callCpp.pAddInts(a, b)
  File "callCpp.pyx", line 16, in callCpp.pAddInts (callCpp.cpp:952)
    def pAddInts(int a, int b):
TypeError: __int__ returned non-int (type int)

No problems @all with double and double*, but ints don't work.. Whats the problem here? Thanks!

mneuner
  • 433
  • 5
  • 25
  • It might be helpful to give the compiler you're using (I don't know if it's relevant but it could be). Also you should probably be doing `cdef extern from "square.hpp"` (i.e. the header file without the implementation). However, I doubt that's the problem. I can't reproduce the bug though, so don't think I can actually help. – DavidW May 13 '15 at 10:29
  • Anaconda uses the gcc (which is included). The problem also occurs without any C-function call, even if i just assign the python int to a cdef int. – mneuner May 13 '15 at 10:37

1 Answers1

0

Ok got the solution: mingw is NOT suitable for this job, it has to be Microsoft VC++. This helped perfectly: https://github.com/cython/cython/wiki/InstallingOnWindows

mneuner
  • 433
  • 5
  • 25