Problems with compiling C code in Python

后端 未结 3 379
萌比男神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:06

    Comment the line in setup.py that say libraries=['m'], and run again.

    The need to link to m might be a GCC thing to link Math library, that is managed by MSVCR in Windows environment.

    0 讨论(0)
  • 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)]
    
      )
    
    0 讨论(0)
  • 2021-01-25 15:14

    And if I only comment

    libraries=['m']
    

    and use

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

    then I get lots of warning (not errors hopefully) whose final part is:

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL / nologo /INCREMENTAL:NO /LIBPATH:C:\Anaconda\libs /LIBPATH:C:\Anaconda\PCbuild\am d64 /EXPORT:initutilFunctions_C build\temp.win-amd64-2.7\Release\utilFunctions.o bj build\temp.win-amd64-2.7\Release\cutilFunctions.obj /OUT:C:\Anaconda\sms-tool s-master\software\models\utilFunctions_C\utilFunctions_C.pyd /IMPLIB:build\temp. win-amd64-2.7\Release\utilFunctions_C.lib /MANIFESTFILE:build\temp.win-amd64-2.7 \Release\utilFunctions_C.pyd.manifest cutilFunctions.obj : warning LNK4197: export 'initutilFunctions_C' specified mul tiple times; using first specification Creating library build\temp.win-amd64-2.7\Release\utilFunctions_C.lib and obj ect build\temp.win-amd64-2.7\Release\utilFunctions_C.exp

    I think the problem is now resolved. Thank you LPs!!

    0 讨论(0)
提交回复
热议问题