Python Fortran 模块:LNK1112`模块机器类型 'X86' 与目标机器类型 'x64' 冲突

Python module with Fortran: LNK1112 `module machine type 'X86' conflicts with target machine type 'x64'`

所以最近我一直在学习关于编程和编译以及其他东西如何工作的绝对堆栈,但这有点超出了我的理解范围。目前,我正在尝试安装 pyigrf12,这样我就可以通过某种方式在 Python(我的大部分工作都在这里进行)中使用 IGRF。我的第一个问题是,因为这个模型是用 Fortran 开发的,所以要找到合适的编译器。我使用 MinGW 安装了 g77 和 gfortran 等。

每个编译器给我不同的错误。当 setup.py 默认使用 g77 时,由于 "Invalid form for assignment..." 错误,在此过程中我得到了 "failed with exit status 1" 几次。所以我重命名了 g77.exe 二进制文件,以便 setup.py 被迫使用 gfortran.exe (我不确定如何指定要使用哪个编译器,这都是命令行)。

这个编译器在这个过程中走得更远,但最终以 "failed with exit status 1112" 终止。查看输出,编译器似乎遇到了"fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'"。谷歌搜索这个错误,我遇到了几个参考这个问题的论坛。 proposed solution in each case 似乎假设我使用的是 Visual Studio 环境,可以单击以更改“/MACHINE:IX86”标志。

这看起来很简单,但是可以在命令行中完成吗?如果是这样,如何?目前我对 运行 setup.py 脚本所做的一切是

python setup.py develop

在命令提示符中(我在 Windows 机器上)。任何帮助将不胜感激!

编辑:我写的全部输出如下。请注意,我没有对任何内容进行任何更改 - 到目前为止我唯一可以控制的是编译器。其他一切都是 pyigrf 的一部分。虽然在这个模块的编译中看起来确实可能存在一些问题,但我想知道是否有任何解决方法。因为它看起来像是某种旗帜……我不确定。真诚地希望出现某种奇迹。这是:

running develop
running build_scripts
running egg_info
running build_src
build_src
building extension "igrf12" sources
f2py options: ['--quiet']
  adding 'build\src.win-amd64-2.7\build\src.win-amd64-2.7\fortranobject.c' to sources.
  adding 'build\src.win-amd64-2.7\build\src.win-amd64-2.7' to include_dirs.
build_src: building npy-pkg config files
writing requirements to pyigrf12.egg-info\requires.txt
writing pyigrf12.egg-info\PKG-INFO
writing top-level names to pyigrf12.egg-info\top_level.txt
writing dependency_links to pyigrf12.egg-info\dependency_links.txt
reading manifest file 'pyigrf12.egg-info\SOURCES.txt'
writing manifest file 'pyigrf12.egg-info\SOURCES.txt'
running build_ext
customize MSVCCompiler
customize MSVCCompiler using build_ext
customize GnuFCompiler
Could not locate executable g77
Could not locate executable f77
customize IntelVisualFCompiler
Could not locate executable ifort
Could not locate executable ifl
customize AbsoftFCompiler
Could not locate executable f90
customize CompaqVisualFCompiler
Could not locate executable DF
customize IntelItaniumVisualFCompiler
Could not locate executable efl
customize Gnu95FCompiler
Found executable D:\MinGW\bin\gfortran.exe
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
building 'igrf12' extension
compiling C sources
C:\Users\XXXXX\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Ibuild\src.win-amd64-2.7\build\src.win-amd64-2.7 -IC:\ProgramData\Anaconda2\lib\site-packages\numpy\core\include -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC /Tcbuild\src.win-amd64-2.7\igrf12module.c /Fobuild\temp.win-amd64-2.7\Release\build\src.win-amd64-2.7\igrf12module.obj
C:\Users\XXXXX\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Ibuild\src.win-amd64-2.7\build\src.win-amd64-2.7 -IC:\ProgramData\Anaconda2\lib\site-packages\numpy\core\include -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC /Tcbuild\src.win-amd64-2.7\build\src.win-amd64-2.7\fortranobject.c /Fobuild\temp.win-amd64-2.7\Release\build\src.win-amd64-2.7\build\src.win-amd64-2.7\fortranobject.obj
compiling Fortran sources
Fortran f77 compiler: D:\MinGW\bin\gfortran.exe -Wall -g -ffixed-form -fno-second-underscore -O0
Fortran f90 compiler: D:\MinGW\bin\gfortran.exe -Wall -g -fno-second-underscore -O0
Fortran fix compiler: D:\MinGW\bin\gfortran.exe -Wall -g -ffixed-form -fno-second-underscore -Wall -g -fno-second-underscore -O0
compile options: '-Ibuild\src.win-amd64-2.7\build\src.win-amd64-2.7 -IC:\ProgramData\Anaconda2\lib\site-packages\numpy\core\include -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC -c'
gfortran.exe:f77: fortran/igrf12.f
C:\Users\XXXXX\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:d:\mingw\lib\gcc\mingw32.3.0 /LIBPATH:d:\mingw\lib /LIBPATH:C:\ProgramData\Anaconda2\libs /LIBPATH:C:\ProgramData\Anaconda2\PCbuild\amd64 /LIBPATH:C:\ProgramData\Anaconda2\PC\VS9.0\amd64 /LIBPATH:C:\ProgramData\Anaconda2\libs /LIBPATH:C:\ProgramData\Anaconda2\PCbuild\amd64 /LIBPATH:C:\ProgramData\Anaconda2\PC\VS9.0\amd64 /EXPORT:initigrf12 build\temp.win-amd64-2.7\Release\build\src.win-amd64-2.7\igrf12module.obj build\temp.win-amd64-2.7\Release\build\src.win-amd64-2.7\build\src.win-amd64-2.7\fortranobject.obj build\temp.win-amd64-2.7\Release\fortran\igrf12.o /OUT:igrf12.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\build\src.win-amd64-2.7\igrf12.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\build\src.win-amd64-2.7\igrf12.pyd.manifest
build\temp.win-amd64-2.7\Release\fortran\igrf12.o : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

从日志看来,您安装了 32 位版本的 gfortran。您需要 64 位版本才能与工具链的其余部分兼容。

为了确保执行:gfortran -v并检查版本信息。