I am new to using both f2py and meson. I ran f2py to get the pyfilermodule.c file and the wrappers. Then I created a meson .build file to do the compile and linking. I am getting close but I can get past this LNK2019.
F2py output a 2 python wrappers and the pyfilermodule.c file. The .o files have previously been compiled, they are included to be linked into the module.
[Error message]
(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
meson.build file
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)
I tried to reorder the list of files in meson.build but that had no impact. I'm not sure what I need to modify or include.
The real error is the first one, LNK4098, saying that you have incompatible run-time library settings among the object files being linked. Intel Fortran doesn't care about this, or at least you won't get other link errors, but MSVC references different external symbols depending on which library set you specified when compiling.
I can't tell you exactly what to change, since I don't see all the compile commands, but Intel Fortran defaults to using the DLL libraries (MSVCRT), and some of your C code is compiled to use the static libraries (libucrt). Make these consistent and the errors should go away.