Thread: Calling Fortran Subroutine!!! COMPLEX!!!!

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    8

    Calling Fortran Subroutine!!! COMPLEX!!!!

    I'd like to call a fortran subroutine from my c program.

    The complie error i have so far is :
    Code:
    warning: implicit declaration of function 'MIEV0'
    Im not sure how to link the fortran function in the c program.

    heres my code.
    Thanks

    Code:
    #include <stdio.>
    
    int main()
    {
    //declare all the variables to send to subroutine
    //...enter in variables for the external subroutine
    // which includes a struct for complex numbers
    
    // call fortran subroutine
    MIEV0(&variable1,&variable2....);
    
    //prints a result.
    return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    First, you need to tell us which C and Fortran compilers you're using.

    Mixed-language programming is tricky, and generally only possible between implementations provided by the same manufacturer (of your compilers).

    Next you need to read up on things like calling conventions in your compiler manual.

    For example, C++ calls C by doing this
    extern "C" void myFunc();

    When you know what the calling convention is, and how that related to the parameters you're trying to pass, then maybe you do something like this:
    extern "Fortran" void MIEV0();
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    8
    Sorry i forgot :s

    The complier is gcc

    Code:
    gcc fsubroutine.f c2fmie.c -lgfortran
    the compile error i get is

    Code:
    /tmp/ccSdcUqo.o: In function `main':
    c2fmie.c:(.text+0x32e): undefined reference to `MIEV0'
    collect2: ld returned 1 exit status

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. real-world apps in C++ (preferably simple)?
    By Aisthesis in forum C++ Programming
    Replies: 13
    Last Post: 06-12-2009, 01:03 PM
  2. Fortran 90 Subroutine in Borland C++ builder
    By ahn1162 in forum C++ Programming
    Replies: 5
    Last Post: 06-14-2007, 10:50 AM
  3. Why am I getting 'undelcared identifier' ???
    By Bill83 in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2006, 01:00 PM
  4. how to call a fortran subroutine
    By angel6700 in forum C++ Programming
    Replies: 7
    Last Post: 09-26-2002, 04:57 PM
  5. Problem from texbook
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-26-2002, 04:55 AM

Tags for this Thread