By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

Calling a fortran subroutine from Visual C++

P: n/a
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++?
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Ray J." <Ray J.@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
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++?


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

Nov 17 '05 #2

P: n/a
"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message
news:uo**************@TK2MSFTNGP09.phx.gbl...
"Ray J." <Ray J.@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...

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.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.