Problems with compiling C code in Python

后端 未结 3 382
萌比男神i
萌比男神i 2021-01-25 14:27

I use Anaconda for Python 2.7.10 in Windows 7, 64 bit. I also use Visual Studio 2010. I installed Microsoft Visual Studio for Python.

When I try to compile a C code in

3条回答
  •  春和景丽
    2021-01-25 15:08

    Just removing .. libraries=['m'] .. from ext_modules helped me compile on windows 2010 too. No errors or warnings. This is how it looks finally,

    ext_modules = [Extension("utilFunctions_C",sourcefiles , include_dirs=py_inc + np_inc)]
    

    Thanks a bunch

    Edit .....

    Here is entire code for compileModule.py Please refer to comments for details.

    from distutils.core import setup, Extension
    from distutils.sysconfig import *
    from distutils.util import *
    from Cython.Distutils import build_ext
    import numpy
    import os
    import os.path
    
    #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
    
    try:
       from distutils.command.build_py import build_py_2to3 \
       as build_py
    except ImportError:
       from distutils.command.build_py import build_py
    
    try:
       from Cython.Distutils import build_ext
    except ImportError:
       use_cython = False
    else:
       use_cython = True
    
    
    py_inc = [get_python_inc()]
    
    np_lib = os.path.dirname(numpy.__file__)
    np_inc = [os.path.join(np_lib, 'core/include')]
    ext_inc = os
    
    sourcefiles = ["utilFunctions.c", "cutilFunctions.pyx"]
    
    setup(
        cmdclass = {'build_ext': build_ext},
        #ext_modules = [Extension("utilFunctions_C",sourcefiles, libraries=['m'], include_dirs=py_inc + np_inc)]
        ext_modules = [Extension("utilFunctions_C",sourcefiles , include_dirs=py_inc + np_inc)]
    
      )
    

提交回复
热议问题