Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4563750
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:24:12+00:00 2026-05-21T18:24:12+00:00

I would like to call some functions from a Fortran shared library in Python.

  • 0

I would like to call some functions from a Fortran shared library in Python. I have found some links on the net and read them, and according what I found, I should do

libadd = cdll.LoadLibrary('./libbin.so') 

to load the shared object. However, this shared object includes some symbols from another shared library. I read the help of cdll however it does not seem possible to load several shared object files at the same time. How may I call functions from this Fortran library, which is most probably compiled by the Intel Fortran compiler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T18:24:13+00:00Added an answer on May 21, 2026 at 6:24 pm

    You’ll need to know the signatures of the functions in the shared object. Do you have the source code, or some reference which explains the function names and argument types?

    For example, I have this source code (mult.f90):

    integer function multiply(a, b)
        integer, intent(in) :: a, b
        multiply = a * b
    end function multiply
    

    .. and to demonstrate how you can load and use multiple shared objects at once, I also have (add.f90):

    integer function addtwo(a, b)
        integer, intent(in) :: a, b
        addtwo = a + b
    end function addtwo
    

    Compile, examine symbols:

    % gfortran-4.4 -shared -fPIC -g -o mult.so mult.f90
    % gfortran-4.4 -shared -fPIC -g -o add.so add.f90
    % nm -ao mult.so | grep multiply
    mult.so:00000000000005cc T multiply_
    

    Notice the symbol name in the shared object has an underscore appended. Since I have the source, I know that the signature is multiply_(int *a, int *b), so it is easy to invoke that function from ctypes:

    from ctypes import byref, cdll, c_int
    
    mult = cdll.LoadLibrary('./mult.so')
    add = cdll.LoadLibrary('./add.so')
    a = c_int(2)
    b = c_int(4)
    print mult.multiply_(byref(a), byref(b))
    print add.addtwo_(byref(a), byref(b))
    

    Output:

    8
    6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to call python script files from my c++ program. I am
I would like to call Perl script files from my c++ program. I am
I would like to call my unmanaged C++ libraries from my C# code. What
From my bash shell I would like to call a program n times with
I have a controller action which I would like to call another controller action.
I have a Silverlight application in which I would like to call a WCF
I am using VB.Net WinForms. I would like to call the Adobe Reader 9
I would like to call C# service with using PHP, anyone know how to
I would like to call FindLast on a collection which implements IEnumerable , but
I would like to call a windows program within my code with parameters determined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.