itcarroll / scikit-build-sample-projects

Sample projects demonstrating use of scikit-build
0 stars 0 forks source link

unable to link hello-f2py to f2py #1

Open itcarroll opened 1 year ago

itcarroll commented 1 year ago

Attempting to add a hello-f2py example to the scikit-build-sample-projects repository. Build is successful but linking fails: something about the lib_f2py_runtime_library.a not getting built with the -fPIC flag (I think).

[8/9] Linking Fortran shared module hello/_hello.cpython-310-x86_64-linux-gnu.so
      FAILED: hello/_hello.cpython-310-x86_64-linux-gnu.so
      : && /usr/bin/gfortran -fPIC -O3 -DNDEBUG -O3  -Wl,--unresolved-symbols=ignore-all -Wl,--version-script="/home/icarroll/tmp/skb/projects/hello-f2py/_skbuild/linux-x86_64-3.10/cmake-build/hello/CMakeFiles/_hello-version-script.map" -shared  -o hello/_hello.cpython-310-x86_64-linux-gnu.so hello/CMakeFiles/_hello.dir/_hellomodule.c.o hello/CMakeFiles/_hello.dir/_hello-f2pywrappers.f.o  lib_f2py_runtime_library.a && :
      /usr/bin/ld: lib_f2py_runtime_library.a(fortranobject.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: final link failed: Nonrepresentable section on output

Paging @xoviat, creator of add_f2py_target, for advice if available 🙇.

itcarroll commented 1 year ago

Current status is that I can verify the F2PY parts are all working by compiling with numpy.f2py and a pip install -e . As in ...

$ cd hello_f2py
$ python -m numpy.f2py -c hello.f90 _hello.pyf
...
$ cd ..
$ pip install -e .
$ pytest

The error above arises with pip wheel . or pip install ..

itcarroll commented 1 year ago

Adding set_target_properties(_f2py_runtime_library PROPERTIES POSITION_INDEPENDENT_CODE ON) has silenced the error above.

On to an undefined symbols error at runtime ...

ImportError while importing test module '/home/icarroll/tmp/skb/projects/hello-f2py/tests/test_hello_f2py.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../../miniconda3/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_hello_f2py.py:1: in <module>
    from hello_f2py import hello
venv/lib/python3.10/site-packages/hello_f2py/__init__.py:1: in <module>
    from ._hello import hello
E   ImportError: /home/icarroll/tmp/skb/projects/hello-f2py/venv/lib/python3.10/site-packages/hello_f2py/_hello.cpython-310-x86_64-linux-gnu.so: undefined symbol: hello_