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
    Location
    Waterloo, Texas
    Posts
    5,652
    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 <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

  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, 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