Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Call fortran in C++ project
Hi, All:
I plan to using a fortran 90 program in C++. I have no experience
about that, and I have some question about that.

1. I think I have two methods to using the fortran 90 program.
First, compile all the .f90 and .cpp to .obj, and link them. Second,
make the fortran 90 program to a dll, and call it in C++ project. I
want to know, which is better, and how I should do?
2. In the fortran 90 program, there many Types. How can I using
them in C++.

Thank you very much.

Report this thread to moderator Post Follow-up to this message
Old Post
FlyVenus
03-31-08 10:51 AM


Re: Call fortran in C++ project
FlyVenus wrote:
> Hi, All:
>      I plan to using a fortran 90 program in C++. I have no experience
> about that, and I have some question about that.
>
>      1. I think I have two methods to using the fortran 90 program.
> First, compile all the .f90 and .cpp to .obj, and link them. Second,
> make the fortran 90 program to a dll, and call it in C++ project. I
> want to know, which is better, and how I should do?

The second method is likely to involve less pain in terms of figuring
out which linker to use, etc.  You will still need to use the manual for
your Fortran compiler to make sure that your Fortran routine in the dll
is designed correctly to be called from C++.

>      2. In the fortran 90 program, there many Types. How can I using
> them in C++.

See the manual for your Fortran compiler on mixed language programming.
Possibly, all you will need to do is specify SEQUENCE and make sure
that the TYPEs are compatible with C++ (i.e. no pointers or allocatables).

Report this thread to moderator Post Follow-up to this message
Old Post
Craig Powers
04-01-08 03:01 AM


Re: Call fortran in C++ project
On Apr 1, 2:47 am, Craig Powers <eni...@hal-pc.org> wrote:
> FlyVenus wrote: 
> 
>
> The second method is likely to involve less pain in terms of figuring
> out which linker to use, etc.  You will still need to use the manual for
> your Fortran compiler to make sure that your Fortran routine in the dll
> is designed correctly to be called from C++.
> 
>
> See the manual for your Fortran compiler on mixed language programming.
>   Possibly, all you will need to do is specify SEQUENCE and make sure
> that the TYPEs are compatible with C++ (i.e. no pointers or allocatables).=[/color
]


Thank you.
I use the Intel=AE Visual Fortran Compiler. And the bad news is the
TYPEs contain lots of pointers...

Report this thread to moderator Post Follow-up to this message
Old Post
FlyVenus
04-01-08 03:02 AM


Re: Call fortran in C++ project
On Mon, 31 Mar 2008 18:33:05 -0700 (PDT), FlyVenus <duguguiyu@gmail.com>
wrote:

>I use the Intel® Visual Fortran Compiler. And the bad news is the
>TYPEs contain lots of pointers...

There is a detailed chapter in the Intel Visual Fortran documentation on
mixed-language programming.  You should also look at the Fortran 2003 C
Interoperability features supported by that compiler. The use of pointers is
not necessarily a big problem.

If you need more help, feel free to ask in the Intel user forum at
[url]http://softwarecommunity.intel.com/isn/Community/en-US/forums/1005/ShowForum.aspx[
/url]
--
Steve Lionel
Developer Products Division
Intel Corporation
Nashua, NH

For email address, replace "invalid" with "com"

User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://support.intel.com/support/pe...cetools/fortran
My Fortran blog
http://www.intel.com/software/drfortran

Report this thread to moderator Post Follow-up to this message
Old Post
Steve Lionel
04-02-08 03:39 AM


Re: Call fortran in C++ project
FlyVenus wrote:
> On Apr 1, 2:47 am, Craig Powers <eni...@hal-pc.org> wrote: 
>
> Thank you.
> I use the Intel® Visual Fortran Compiler. And the bad news is the
> TYPEs contain lots of pointers...

If they have POINTERs in them, then I would think they'll be pretty much
impossible to use directly in C++ without making the C++ code dependent
on the IVF "dope vector" implementation (which is possible, but
undesirable due to extreme lack of portability).  However, it may be
possible to come up with a scheme where the objects are managed in
Fortran, with an interface to manipulate them that is exposed to C++.

Report this thread to moderator Post Follow-up to this message
Old Post
Craig Powers
04-02-08 03:39 AM


Re: Call fortran in C++ project
On Tue, 01 Apr 2008 13:32:14 -0400, Craig Powers <enigma@hal-pc.org> wrote:

>If they have POINTERs in them, then I would think they'll be pretty much
>impossible to use directly in C++ without making the C++ code dependent
>on the IVF "dope vector" implementation (which is possible, but
>undesirable due to extreme lack of portability).  However, it may be
>possible to come up with a scheme where the objects are managed in
>Fortran, with an interface to manipulate them that is exposed to C++.

My advice, if one has the flexibility, is to use the F2003 C Interop feature
s.
Give the derived type the BIND(C) attribute and have it contain components o
f
TYPE(C_PTR).  One can use functions in ISO_C_BINDING to convert between that
and Fortran POINTER.  This is supported by IVF and is portable (to other
compilers supporting this F2003 feature.)

--
Steve Lionel
Developer Products Division
Intel Corporation
Nashua, NH

For email address, replace "invalid" with "com"

User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://support.intel.com/support/pe...cetools/fortran
My Fortran blog
http://www.intel.com/software/drfortran

Report this thread to moderator Post Follow-up to this message
Old Post
Steve Lionel
04-02-08 03:39 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 02:13 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.