Call Fortran function from .dll/.so

This is a discussion on Call Fortran function from .dll/.so within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I want (again) to call a Fortran function from C++. Now I know how to do this when ...

  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
    Posts
    5,439
    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:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,699
    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, 09: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, 06: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, 01:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21