Thread: Fortran 90 Subroutine in Borland C++ builder

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    1

    Fortran 90 Subroutine in Borland C++ builder

    I have a big problem with "Borland C++ Buiolder 6" & FORTRAN90 (Fortan power station 4). I have to use a FORTRAN 90 subroutine. I use this line in my C++ program:

    extern "C" subroutine_name_(variable);

    but there is a problem in compiling the program. I recive this error massage:

    [Linker Error] Unresolved external 'subroutine_name' referenced from C:\PROJECT\subroutine_name.OBJ

    any help is appreciated.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    ive never used extern so im just guessing.

    it seems that the function 'subroutine_name(variable)' doesnt exist. are you following a tutorial or something that says to do this? if so i imagine you have to replace 'subroutine_name' with the name of a function and (variable) with whatever the function accepts.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by ahn1162 View Post
    I have a big problem with "Borland C++ Buiolder 6" & FORTRAN90 (Fortan power station 4). I have to use a FORTRAN 90 subroutine. I use this line in my C++ program:

    extern "C" subroutine_name_(variable);

    but there is a problem in compiling the program. I recive this error massage:

    [Linker Error] Unresolved external 'subroutine_name' referenced from C:\PROJECT\subroutine_name.OBJ

    any help is appreciated.
    Probably the symbol naming method is different between the C++ compiler and the Fortran compiler. Could be the C++ compiler is inserting a leading underscore and the Fortran compiler is not. It doesn't seem to be a mangling problem because you've properly declared it extern "C".

    But even if you can get it to resolve the symbol, I'm not sure the calling convention is compatible between C++ and Fortran. You might have to write a thunk using some assembly language.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    You might have to write a thunk using some assembly language.
    Or just give the correct function type like __cdecl, __stdcall, __fastcall, and others
    http://msdn2.microsoft.com/en-us/lib...fy(VS.71).aspx
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You have to read the documentation to see how mixed language programs are built for your compiler. There is nothing standard about the way this is done.
    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.

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by vart View Post
    Or just give the correct function type like __cdecl, __stdcall, __fastcall, and others
    Well, if one of those matches the convention expected by the Fortran compiler, it could work. But the answer won't be found in the Microsoft docs, since this is a third-party Fortran compiler.

    Another thing to watch out for is that arguments in Fortran are passed BY REFERENCE, not by value, which is very different from C and C++. It might be as simply as just declaring all the arguments to be pointers, then again, maybe not.

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 to C Conversion
    By m_naseer in forum C Programming
    Replies: 1
    Last Post: 05-05-2008, 03:43 PM
  3. THE END - Borland C++ Builder, Delphi, J Builder?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 02-28-2006, 11:23 PM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  5. how to call a fortran subroutine
    By angel6700 in forum C++ Programming
    Replies: 7
    Last Post: 09-26-2002, 04:57 PM