zoukankan      html  css  js  c++  java
  • 编译Cython代码时遇到的问题: fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'

    使用python setup.py build_ext --inplace命令编译cython代码, 出现以下错误: 

    Compiling cython_example.pyx because it changed.
    [1/1] Cythonizing cython_example.pyx
    D:python_virtualenvigdatalibsite-packagesCythonCompilerMain.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in
    a later release! File: D:学习igdatalearncython_testcython_example.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)
    running build_ext
    building 'cython_test.cython_example' extension
    creating build
    creating build	emp.win-amd64-3.6
    creating build	emp.win-amd64-3.6Release
    C:Program Files (x86)Microsoft Visual Studio 14.0VCincl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-Id:program filespython361include" "-Id:program filespython361includ
    e" "-IC:Program Files (x86)Microsoft Visual Studio 14.0VCINCLUDE" "-IC:Program Files (x86)Windows Kits10include10.0.10240.0ucrt" "-IC:Program Files (x86)Windows Kits
    8.1includeshared" "-IC:Program Files (x86)Windows Kits8.1includeum" "-IC:Program Files (x86)Windows Kits8.1includewinrt" /Tccython_example.c /Fobuild	emp.win-amd64
    -3.6Releasecython_example.obj
    cython_example.c
    creating D:学习igdatalearncython_testcython_test
    C:Program Files (x86)Microsoft Visual Studio 14.0VCinlink.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:d:program filespython361
    Libs" /LIBPATH:D:python_virtualenvigdatalibs /LIBPATH:D:python_virtualenvigdataPCbuildamd64 "/LIBPATH:C:Program Files (x86)Microsoft Visual Studio 14.0VCLIBamd64"
    "/LIBPATH:C:Program Files (x86)Windows Kits10lib10.0.10240.0ucrtx64" "/LIBPATH:C:Program Files (x86)Windows Kits8.1libwinv6.3umx64" /EXPORT:PyInit_cython_example b
    uild	emp.win-amd64-3.6Releasecython_example.obj /OUT:D:学习igdatalearncython_testcython_testcython_example.cp36-win_amd64.pyd /IMPLIB:build	emp.win-amd64-3.6Releasec
    ython_example.cp36-win_amd64.lib
    python36.lib(python36.dll) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe' failed with exit status 1112
    

    解决:

      报错的意思是系统环境是64位windows系统,使用的C编译工具却是32位的。
      windows系统中'x86'表示32位。
      上面这个错的主要问题是使用的link.exe是32位的,只要改成64位的link.exe就没有问题了。
      

      环境: windows64位, python 64位, python3.6.1
      第一步:
        找到windows的系统环境变量path:
        将"C:Program Files (x86)Microsoft Visual Studio 14.0VCinamd64;" 加在path最前面,这样就可以优先使用64位的link.exe。
      第二步:
        新建一个Dos窗口, 执行 "echo %PATH%" ,使环境变量立即生效。(在前面建好的DOS窗口下执行没有用)

      第三步:
        如果是在pycharm的Terminal中执行的 python setup.py build_ext --inplace命令,还需要先重启pycharm,再在其中执行编译命令才会有效。

        DOS的话新建一个DOS窗口即可。

    解决了上面这个问题,又出现了一个新问题:

    running build_ext
    building 'cython_test.cython_example' extension
    C:Program Files (x86)Microsoft Visual Studio 14.0VCinamd64cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-Id:program filespython361include" "-Id:program filespython361include" "-IC:Program Files (x86)Microsoft Visual
    Studio 14.0VCINCLUDE" "-IC:Program Files (x86)Windows Kits10include10.0.10240.0ucrt" "-IC:Program Files (x86)Windows Kits8.1includeshared" "-IC:Program Files (x86)Windows Kits8.1includeum" "-IC:Program Files (x
    86)Windows Kits8.1includewinrt" /Tccython_example.c /Fobuild	emp.win-amd64-3.6Releasecython_example.obj
    cython_example.c
    C:Program Files (x86)Microsoft Visual Studio 14.0VCinamd64link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:d:program filespython361Libs" /LIBPATH:D:python_virtualenvigdatali
    bs /LIBPATH:D:python_virtualenvigdataPCbuildamd64 "/LIBPATH:C:Program Files (x86)Microsoft Visual Studio 14.0VCLIBamd64" "/LIBPATH:C:Program Files (x86)Windows Kits10lib10.0.10240.0ucrtx64" "/LIBPATH:C:Program F
    iles (x86)Windows Kits8.1libwinv6.3umx64" /EXPORT:PyInit_cython_example build	emp.win-amd64-3.6Releasecython_example.obj /OUT:D:学习igdatalearncython_testcython_testcython_example.cp36-win_amd64.pyd /IMPLIB:build	
    emp.win-amd64-3.6Releasecython_example.cp36-win_amd64.lib
    cython_example.obj : warning LNK4197: export 'PyInit_cython_example' specified multiple times; using first specification
       Creating library build	emp.win-amd64-3.6Releasecython_example.cp36-win_amd64.lib and object build	emp.win-amd64-3.6Releasecython_example.cp36-win_amd64.exp
    Generating code
    Finished generating code
    LINK : fatal error LNK1158: cannot run 'rc.exe'
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe' failed with exit status 1158 

    解决:
      错误的意思是缺少rc.exe文件,这个文件在C:Program Files (x86)Windows Kits8.1inx64下,只需要将该目录下的 rc.exe 和 rcdll.dll拷贝一份粘贴到link.exe所在目录C:Program Files (x86)Microsoft Visual Studio 14.0VCinamd64下即可。

      如果是32位系统,则是将C:Program Files (x86)Windows Kits8.1inx86下的rc.exe和rcdll.dll粘贴到C:Program Files (x86)Microsoft Visual Studio 14.0VCin下。

  • 相关阅读:
    解决Data truncation: Truncated incorrect DOUBLE value: 'xxxxxxx';
    免费LOGO在线生成+免费图床 (亲测可用)
    解决问题:bat脚本手动执行没问题,自动执行不成功
    flask上线部署————“WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.”
    钉钉机器人自动推送测试报告
    Python 自动化测试报告通过钉钉机器人推送通知
    转载:如何将新建的项目完整的提交到gitlab上?
    GIT推送时,空文件夹无法添加
    ddt+excel接口自动化测试-HtmlTestRunner报告中用例名称显示excel中自定义的名称
    Exp9 Web安全基础 20154301仉鑫烨
  • 原文地址:https://www.cnblogs.com/hufulinblog/p/10368722.html
Copyright © 2011-2022 走看看