Calling Fortran Subroutine!!! COMPLEX!!!!

This is a discussion on Calling Fortran Subroutine!!! COMPLEX!!!! within the C Programming forums, part of the General Programming Boards category; I'd like to call a fortran subroutine from my c program. The complie error i have so far is : ...

  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
    32,849
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    32,849
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02:03 PM
  2. Fortran 90 Subroutine in Borland C++ builder
    By ahn1162 in forum C++ Programming
    Replies: 5
    Last Post: 06-14-2007, 11: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, 05:57 PM
  5. Problem from texbook
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-26-2002, 05:55 AM

Tags for this Thread


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