我刚开始使用 f2py 和介子。我运行 f2py 来获取 pyfilermodule.c 文件和包装器。然后我创建了一个介子 .build 文件来进行编译和链接。我已经很接近了,但我可以通过 LNK2019。
F2py 输出 2 个 python 包装器和 pyfilermodule.c 文件。 .o 文件之前已经编译过,它们包含在链接到模块中。
[错误信息]
(aeo2025_py311) L:\main\jid\git\NEMS\source\tran>L:\main\jid\git\aeo2025_py311\Scripts\meson.exe compile -C builddir
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.EXE" -C //nemsfs.eia.doe.gov/L/main/jid/git/NEMS/source/tran/builddir
ninja: Entering directory `//nemsfs.eia.doe.gov/L/main/jid/git/NEMS/source/tran/builddir'
[0/1] Regenerating build files.The Meson build system
Version: 1.2.3
Source dir: \\nemsfs.eia.doe.gov\L\main\jid\git\NEMS\source\tran
Build dir: \\nemsfs.eia.doe.gov\L\main\jid\git\NEMS\source\tran\builddir
Build type: native build
Project name: pyfiler
Project version: 0.1
Fortran compiler for the host machine: ifort (intel-cl 2021.10.0)
Fortran linker for the host machine: xilink.exe xilink 2021.10.0
C compiler for the host machine: cl (msvc 19.37.32824 "Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32824 for x64")
C linker for the host machine: link link 14.37.32824.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program python3 found: YES (\\nemsfs\l\main\jid\git\aeo2025_py311\Scripts\python.exe)
Build targets in project: 1
pyfiler 0.1
User defined options
buildtype: release
Found ninja-1.11.0 at "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.EXE"
Cleaning... 1 files.
[6/6] Linking target pyfiler.cp311-win_amd64.pyd
FAILED: pyfiler.cp311-win_amd64.pyd
"link" /MACHINE:x64 /OUT:pyfiler.cp311-win_amd64.pyd ../filer.o ../fwk1io.o ../cio4wk1.o ../gdxf9def.o ../gdxf9glu.o ../filemgr.o ../scedes_reader.o ../fm.o ../nemswk1.o ../tranfrt.o ../tranair.o ../tran.o pyfiler.cp311-win_amd64.pyd.p/pyfiler.f90.obj pyfiler.cp311-win_amd64.pyd.p/pyfilermodule.c.obj pyfiler.cp311-win_amd64.pyd.p/pyfiler-f2pywrappers2.f90.obj pyfiler.cp311-win_amd64.pyd.p/9ba805d9903b1eb1a82ce984fd7ee121a92d1e74_.._.._f2py_src_fortranobject.c.obj "/nologo" "/release" "/nologo" "/OPT:REF" "/DLL" "/IMPLIB:pyfiler.cp311-win_amd64.lib" "C:\Python311\libs\python311.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"
Creating library pyfiler.cp311-win_amd64.lib and object pyfiler.cp311-win_amd64.exp
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4217: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'pyfilermodule.c.obj' in function 'f2py_rout_pyfiler_utils_read_filer'
LINK : warning LNK4217: symbol 'malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'pyfilermodule.c.obj' in function 'string_from_pyobj'
LINK : warning LNK4217: symbol 'strncpy' defined in 'libucrt.lib(strncpy.obj)' is imported by 'pyfilermodule.c.obj' in function 'string_from_pyobj'
LINK : warning LNK4217: symbol 'strnlen' defined in 'libucrt.lib(strnlen.obj)' is imported by 'pyfilermodule.c.obj' in function 'string_from_pyobj'
LINK : warning LNK4217: symbol '_wassert' defined in 'libucrt.lib(assert.obj)' is imported by 'pyfilermodule.c.obj' in function 'PyBytes_AS_STRING'
LINK : warning LNK4286: symbol '_wassert' defined in 'libucrt.lib(assert.obj)' is imported by '9ba805d9903b1eb1a82ce984fd7ee121a92d1e74_.._.._f2py_src_fortranobject.c.obj'
LINK : warning LNK4217: symbol '__acrt_iob_func' defined in 'libucrt.lib(_file.obj)' is imported by '9ba805d9903b1eb1a82ce984fd7ee121a92d1e74_.._.._f2py_src_fortranobject.c.obj' in function 'F2PyDict_SetItemString'
LINK : warning LNK4217: symbol '__stdio_common_vfprintf' defined in 'libucrt.lib(output.obj)' is imported by '9ba805d9903b1eb1a82ce984fd7ee121a92d1e74_.._.._f2py_src_fortranobject.c.obj' in function '_vfprintf_l'
LINK : warning LNK4217: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by '9ba805d9903b1eb1a82ce984fd7ee121a92d1e74_.._.._f2py_src_fortranobject.c.obj' in function '_vsnprintf_l'
pyfiler.f90.obj : error LNK2019: unresolved external symbol FILE_MGR referenced in function UTILS_mp_READ_FILER
pyfiler.f90.obj : error LNK2019: unresolved external symbol FILER referenced in function UTILS_mp_READ_FILER
pyfiler.f90.obj : error LNK2019: unresolved external symbol TRAN referenced in function TRAN_RUN_mp_GO_TRAN
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitutils_ referenced in function f2py_init_utils
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitother_ referenced in function f2py_init_other
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinittran_run_ referenced in function f2py_init_tran_run
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitecp_d_cntl_ referenced in function f2py_init_ecp_d_cntl
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinithtrt_improvement_ referenced in function f2py_init_htrt_improvement
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinithtrt_out_ referenced in function f2py_init_htrt_out
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitstate_rps_ referenced in function f2py_init_state_rps
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitcggen_ referenced in function f2py_init_cggen
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinithy_cf_from_m864_ referenced in function f2py_init_hy_cf_from_m864
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitbase_cf_from_m864_ referenced in function f2py_init_base_cf_from_m864
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitintgen_ referenced in function f2py_init_intgen
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitrps_inputs_ referenced in function f2py_init_rps_inputs
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitshours_ referenced in function f2py_init_shours
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitavdscrt_ referenced in function f2py_init_avdscrt
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitaim_grp_ referenced in function f2py_init_aim_grp
pyfilermodule.c.obj : error LNK2019: unresolved external symbol f2pyinitaim_ind_ referenced in function f2py_init_aim_ind
介子.build文件
project('pyfiler',
['c', 'fortran'],
version : '0.1',
meson_version: '>= 1.1.0',
default_options : [
'warning_level=1',
'buildtype=release'
])
py = import('python').find_installation(pure: false)
py_dep = py.dependency()
incdir_numpy = run_command(py,
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
check : true
).stdout().strip()
incdir_f2py = run_command(py,
['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'],
check : true
).stdout().strip()
inc_np = include_directories(incdir_numpy)
includes_files =include_directories ('//nemsfs.eia.doe.gov\\L\main\\jid\\git\\NEMS/includes')
src = include_directories('.')
np_dep = declare_dependency(include_directories: inc_np)
incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src'
inc_f2py = include_directories(incdir_f2py)
fortranobject_c = incdir_f2py / 'fortranobject.c'
inc_np = include_directories(incdir_numpy, incdir_f2py)
py.extension_module('pyfiler',
'pyfiler.f90',
'pyfilermodule.c',
'pyfiler-f2pywrappers2.f90',
fortranobject_c,
include_directories: [inc_np, includes_files,src],
objects: ['filer.o', 'fwk1io.o', 'cio4wk1.o', 'gdxf9def.o', 'gdxf9glu.o', 'filemgr.o', 'scedes_reader.o', 'fm.o' ,'nemswk1.o', 'tranfrt.o', 'tranair.o', 'tran.o'],
dependencies : [
py_dep,
],
install : true)
我尝试对 meson.build 中的文件列表进行重新排序,但这没有任何影响。我不确定我需要修改或包含什么。
真正的错误是第一个错误,LNK4098,表示正在链接的目标文件之间存在不兼容的运行时库设置。 Intel Fortran 不关心这一点,或者至少你不会得到其他链接错误,但 MSVC 根据你在编译时指定的库集引用不同的外部符号。
我无法确切地告诉您要更改什么,因为我没有看到所有编译命令,但 Intel Fortran 默认使用 DLL 库 (MSVCRT),并且您的一些 C 代码被编译为使用静态库 ( libucrt)。使这些一致,错误就会消失。