Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

Calling a fortran subroutine from Visual C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ray J. - 16 Jun 2005 23:00 GMT
I have a C++ program written and compiled on Solaris 8 with gcc. With gcc
lets me compile fortran code along with the C++ program to be able to call
the fortran code as a subroutine.  The specifications for this project have
changed and I am porting the C++ code to Visual C++.  Is there a way to call
fortran code from a C++ program compiled with  Visual C++?
William DePalo [MVP VC++] - 17 Jun 2005 00:23 GMT
>I have a C++ program written and compiled on Solaris 8 with gcc. With gcc
> lets me compile fortran code along with the C++ program to be able to call
[quoted text clipped - 3 lines]
> call
> fortran code from a C++ program compiled with  Visual C++?

It's not clear to me what tools you have. Do you have a Fortran compiler for
Win32? If you do, and if it allows you to build a DLL, then the expedient
thing to do is export your function from the DLL and to call it from a C++
executable. Assuming compatible types and calling conventions VC++ should
have no trouble calling into an external DLL.

I don't believe that MS sells a Fortran compiler. You will find some free
Fortran compilers here:

http://www.thefreecountry.com/compilers/fortran.shtml

though I should tell you that I have no experience with any of them.

Regards,
Will
Norman Diamond - 17 Jun 2005 03:52 GMT
>> I have a C++ program written and compiled on Solaris 8 with gcc. With gcc
>> lets me compile fortran code along with the C++ program to be able to
>> call the fortran code as a subroutine.

I never noticed that, but maybe it's not surprising since the Gnu Fortran
compiler is closely related to gcc.  Depending on your needs, have you tried
Windows Services for Unix?  I've used gcc (though not Gnu Fortran) in that
environment.

>> Is there a way to call fortran code from a C++ program compiled with
>> Visual C++?

Old MSDN libraries used to say how!  Microsoft used to make a Fortran
compiler, they sold the product and it became the DEC Fortran compiler for
Windows, which became the Compaq Fortran compiler for Windows, and then
Compaq or HP sold the product and now it's the Intel Fortran compiler for
Windows.  But MSDN libraries no longer say how to interoperate with it, so
you'll need Intel's documents.

> It's not clear to me what tools you have. [...] if it allows you to build
> a DLL, then the expedient thing to do is export your function from the DLL
> [...]

The big questions are what the types are, and whether there are arrays and
stuff like that.  By the way the declarations in the C++ program will surely
need to be wrapped in extern "C" {}.

> You will find some free Fortran compilers here:
> http://www.thefreecountry.com/compilers/fortran.shtml

Interesting page, thank you.  Hmm, they say that Intel's compiler is free
for personal non-commercial use.  I don't think it was when I hunted it down
a while back.

They also list f2c, which I've used before.  The resulting C code isn't
human readable but it does compile, and can be called from C++ callers.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.