Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29281 Discussions

How to compile a fortran code with a C++ subroutine in Linux system?

mynumber
Beginner
811 Views

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!

0 Kudos
3 Replies
TimP
Honored Contributor III
811 Views
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.
0 Kudos
mynumber
Beginner
811 Views
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?
0 Kudos
TimP
Honored Contributor III
811 Views
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
0 Kudos
Reply