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

时间:2017-11-03 23:26:38

标签: python python-2.7 fortran gfortran

最近,我一直在学习关于编程和编译以及工作原理的绝对堆栈,但这有点超出我的深度。目前,我正在尝试安装pyigrf12,以便我有一些方法可以在Python中使用IGRF(我的大部分工作都在这里)。我的第一个问题是,因为这个模型是在Fortran中开发的,所以找到了一个合适的编译器。我使用MinGW来安装g77和gfortran等。

每个编译器都给我不同的错误。当setup.py默认使用g77时,我得到了#34;以退出状态1"由于"无效的作业形式..."在此过程中出现几次错误。所以我重命名了g77.exe二进制文件,以便setup.py被强制使用gfortran.exe(我不确定如何指定使用哪个编译器,这是所有命令行)。

这个编译器进一步完成了整个过程,但最终终止了"失败,退出状态为1112"。查看输出,编译器似乎遇到了"致命错误LNK1112:模块机器类型' X86'与目标机器类型冲突' 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\9.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\9.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\9.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:d:\mingw\lib\gcc\mingw32\6.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'

1 个答案:

答案 0 :(得分:1)

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

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