目前我正在尝试从Fortran源文件生成(Python?)库文件,以便能够将fortran函数用作Python模块。从这个描述中,你可能已经解决了我并不是特别狡猾(对所有这些都相当新!)所以我试着按照详细的here说明。
目前,我有一个fortran源文件,igrf12.f,我知道它可以使用mingw64包中的64位gfortran编译器正常编译。但是,当我尝试使用f2py编译(?)此源文件时,我得到一堆(LNK2019)错误,说我有未解析的外部。由于源文件正确编译并生成一个工作的.exe文件,如果我使用gfortran,它会让我认为这是f2py,我的安装中的错误,或者我只是没有正确使用它。
我输入的内容:
f2py -c -m igrf_fortran igrf12.f
输出(仅限Fortran部分):
compiling Fortran sources
Fortran f77 compiler: D:\MinGW-w64\mingw64\bin\gfortran.exe -Wall -g -ffixed-form -fno-second-underscore -O0
Fortran f90 compiler: D:\MinGW-w64\mingw64\bin\gfortran.exe -Wall -g -fno-second-underscore -O0
Fortran fix compiler: D:\MinGW-w64\mingw64\bin\gfortran.exe -Wall -g -ffixed-form -fno-second-underscore -Wall -g -fno-second-underscore -O0
compile options: '-Ic:\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7 -IC:\ProgramData\Anaconda2\lib\site-packages\numpy\core\include -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC -c'
gfortran.exe:f77: 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-w64\mingw64\lib\gcc\x86_64-w64-mingw32\7.2.0 /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:initigrf_fortran c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\igrf_fortranmodule.obj c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\fortranobject.obj c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\igrf12.o /OUT:.\igrf_fortran.pyd /IMPLIB:c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\igrf_fortran.lib /MANIFESTFILE:c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\igrf_fortran.pyd.manifest
igrf_fortranmodule.obj : warning LNK4197: export 'initigrf_fortran' specified multiple times; using first specification
Creating library c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\igrf_fortran.lib and object c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\igrf_fortran.exp
igrf12.o : error LNK2019: unresolved external symbol __main referenced in function main
igrf12.o : error LNK2019: unresolved external symbol _gfortran_st_write referenced in function igrf12syn_
igrf12.o : error LNK2019: unresolved external symbol _gfortran_transfer_real_write referenced in function igrf12syn_
igrf12.o : error LNK2019: unresolved external symbol _gfortran_st_write_done referenced in function igrf12syn_
igrf12.o : error LNK2019: unresolved external symbol lround referenced in function ddecdm_
igrf12.o : error LNK2019: unresolved external symbol _gfortran_transfer_character_write referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_st_read referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_transfer_character referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_st_read_done referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_st_open referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_transfer_integer referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_stop_string referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_transfer_real referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_transfer_integer_write referenced in function MAIN__
igrf12.o : error LNK2019: unresolved external symbol _gfortran_set_args referenced in function main
igrf12.o : error LNK2019: unresolved external symbol _gfortran_set_options referenced in function main
.\igrf_fortran.pyd : fatal error LNK1120: 16 unresolved externals
error: Command "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-w64\mingw64\lib\gcc\x86_64-w64-mingw32\7.2.0 /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:initigrf_fortran c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\igrf_fortranmodule.obj c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\fortranobject.obj c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\igrf12.o /OUT:.\igrf_fortran.pyd /IMPLIB:c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\igrf_fortran.lib /MANIFESTFILE:c:\users\XXXXX\appdata\local\temp\tmpmienlh\Release\users\XXXXX\appdata\local\temp\tmpmienlh\src.win-amd64-2.7\igrf_fortran.pyd.manifest" failed with exit status 1120
有趣的是,这是一个非常类似的错误,当我尝试在同一系统上安装this Python模块时,我假设它也使用了f2py。我最初尝试安装此模块是here,但由于这是一个不同(但相关)的问题,我觉得我应该把它放在自己的问题中,而不是进一步编辑原始问题。