- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, all!
I am encountering a problem. I write a C++ code and want to connect it witha fortran code,but I do not know how to compile the fortran program with a C++ subroutine.Do you have any ideas? Thanks!
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As you don't give any specifics, you should be able to get many relevant ideas by looking things up. Your search should include the documentation of your Fortran compiler. In general, if you want it to work with many brands of Fortran, you would use "extern C" to make the interface C-compatible on the C++ side. Then, you could use any C interface example you find to get it working, before tinkering with sugar such as C++ parameters by reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your reply!Unfortunately, I am aprimary learner, and I still do not how to deal with it.
Now I describe my situation in detail.I use the Fortran program so as to generate some kinetics data, and then make data processing by the C++ code. Since thedata at each time step need beprocessed, I want to call the C++ code as a subroutine of the Fortran program.But I do not know how to compile the two files and form a single executable file. BTY,the compilersin the LinuxOSareifc and g++.
Could you tell me detailedly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Make a .o for the C++ code, and include it in the Fortran build. Depending how much C++ you use, you may require C++ library specifications:
icpc -c yourcxx.cpp
ifort yourfort.f yourcxx.o -lstdc++ -lunwind
icpc -c yourcxx.cpp
ifort yourfort.f yourcxx.o -lstdc++ -lunwind

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page