473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Calling a fortran subroutine from Visual C++

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
2 2800
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: NM | last post by:
Hello All I am writing some progam that involves both C++ and Fortran. Some of the existing code is in Fortran. The main program will be in C++ and it will call some Fortran subroutine. All the...
6
by: Adrian | last post by:
I am trying to pass the address of a C++ function into a Fortran routine to enable the Fortran routine to call this C++ function. I have to do it this way as our build process does not allow...
1
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of...
12
by: Bigdakine | last post by:
I don't know if this is the right forum for this, and if not please suggest one which fits. I have to call a fortran sub routine from a C main program. The fortran subroutine statement is ...
5
by: Amit | last post by:
I tried calling a subroutine in a fortran module from C ,but couldn't.I always get the error: undefined reference in the main.o file (main is in C calling the subroutine). for calling the...
11
by: RichN | last post by:
I am developing a c program in Visual Studio .NET 2003. I also have an Intel(R) Fortran compiler for MVS .NET My fortran sourcecode already existed. I started a new fortran project and chose to...
52
by: Nomad.C | last post by:
Hi I've been thinking of learning Fortran as number crunching kinda language for my Physics degree......but then looking around the internet, people are saying that the libraries/ Algorithms once...
3
by: =?Utf-8?B?TWFyZWs=?= | last post by:
Hi As well as trying to call a fortran dll with a structure parameter from a C# front end, we are trying to do this using AssemblyBuilder and MethodInfo to do it dynamically. Ultimately this will...
4
by: nitusa | last post by:
Hey Everyone, I am doing a VB6 to C# conversion and everything was going smoothly until I realized that I needed to call a Fortran 77 (.for) .dll inside my code. I have looked through everything...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.