|
From: FlyVenus on 30 Mar 2008 23:08 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.
From: FlyVenus on 31 Mar 2008 21:33 On Apr 1, 2:47 am, Craig Powers <eni...(a)hal-pc.org> wrote: > 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). Thank you. I use the Intel® Visual Fortran Compiler. And the bad news is the TYPEs contain lots of pointers...
From: Steve Lionel on 1 Apr 2008 09:43 On Mon, 31 Mar 2008 18:33:05 -0700 (PDT), FlyVenus <duguguiyu(a)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 http://softwarecommunity.intel.com/isn/Community/en-US/forums/1005/ShowForum.aspx -- 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/performancetools/fortran My Fortran blog http://www.intel.com/software/drfortran
From: Craig Powers on 1 Apr 2008 13:32 FlyVenus wrote: > On Apr 1, 2:47 am, Craig Powers <eni...(a)hal-pc.org> wrote: >> 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). > > 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++.
From: Steve Lionel on 1 Apr 2008 13:45 On Tue, 01 Apr 2008 13:32:14 -0400, Craig Powers <enigma(a)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 features. Give the derived type the BIND(C) attribute and have it contain components of 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/performancetools/fortran My Fortran blog http://www.intel.com/software/drfortran
|
Pages: 1 Prev: FoX - an XML toolkit for Fortran Next: How to read files with commas as separators? |