Thread: Call Fortran function from .dll/.so

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    Call Fortran function from .dll/.so

    Hi everyone,

    I want (again) to call a Fortran function from C++. Now I know how to do this when I have the source or object file, but I think that it should be possible to do this directly with the .so or .dll ?

    Also, does anyone know a program which lists functions in a .so file, like one can read the exported functions in a .dll file? http://www.nirsoft.net/utils/dll_export_viewer.html

    Thanks a lot in advance!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I don't know about 'nix, but from windows you use the API calls 'LoadLibrary' and 'GetProcAddress', eg:

    Code:
    typedef int ( * foo_function )( double );
    HMODULE
          library = LoadLibrary( "foo.dll" );
    if( library )
    {
          foo_function
                function = foo_function( GetProcAddress( library, "baz" ) );     	
          if( function )
          {
                int 
                      result = function( 2.0 );
          }
          FreeLibrary( library );	
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Static objects you *usually* get the imported symbols loaded in during compile time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  4. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM