OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Python 3.12 f2py linking against libraries not working properly

  • Thread starter Thread starter Jannick
  • Start date Start date
J

Jannick

Guest
With Python 3.11 and the distutils backend I was able to easily compile one interface file and link to an archive with various other precompiled f90 files. Now with meson it seems like this is not possible anymore.

So I have two subroutines:

subroutine1.f90

Code:
subroutine subroutine1
    implicit none
    call subroutine2
    print *, "Inside subroutine1"
end subroutine subroutine1

and

subroutine2.f90

Code:
subroutine subroutine2
    implicit none
    print *, "Inside subroutine2"
end subroutine subroutine2

I compile both files with gfortran -c subroutine1.f90 subroutine2.f90 and put them into an archive by the command ar rcs libmylibrary.a subroutine1.o subroutine2.o. Lastly I have a main file

main.f90

Code:
subroutine main
    implicit none
    call subroutine1()
end subroutine main

and when I use f2py -c main.f90 -m inter -L. -lmylibrary.a I get the interface file. Trying to import the interface in my python file as import inter I get the error: ImportError: /home/XYZ/f2pytest/inter.cpython-312-x86_64-linux-gnu.so: undefined symbol: subroutine1_ and for the life of me I can't figure out why this is not working anymore. When I use the python3.11 version of f2py it compiles no problem.

Any help is greatly appreciated!
<p>With Python 3.11 and the distutils backend I was able to easily compile one interface file and link to an archive with various other precompiled f90 files. Now with meson it seems like this is not possible anymore.</p>
<p>So I have two subroutines:</p>
<p>subroutine1.f90</p>
<pre><code>subroutine subroutine1
implicit none
call subroutine2
print *, "Inside subroutine1"
end subroutine subroutine1
</code></pre>
<p>and</p>
<p>subroutine2.f90</p>
<pre><code>subroutine subroutine2
implicit none
print *, "Inside subroutine2"
end subroutine subroutine2
</code></pre>
<p>I compile both files with <code>gfortran -c subroutine1.f90 subroutine2.f90</code> and put them into an archive by the command <code>ar rcs libmylibrary.a subroutine1.o subroutine2.o</code>. Lastly I have a main file</p>
<p>main.f90</p>
<pre><code>subroutine main
implicit none
call subroutine1()
end subroutine main
</code></pre>
<p>and when I use <code>f2py -c main.f90 -m inter -L. -lmylibrary.a</code> I get the interface file. Trying to import the interface in my python file as <code>import inter</code> I get the error: <code>ImportError: /home/XYZ/f2pytest/inter.cpython-312-x86_64-linux-gnu.so: undefined symbol: subroutine1_</code> and for the life of me I can't figure out why this is not working anymore. When I use the python3.11 version of f2py it compiles no problem.</p>
<p>Any help is greatly appreciated!</p>
 

Latest posts

J
Replies
0
Views
1
Jeff P Chacko
J
Top