Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:08:51+00:00 2026-06-02T13:08:51+00:00

I need to call a Fortran program within a C++ code. The program is

  • 0

I need to call a Fortran program within a C++ code. The program is compiled using an Intel compiler The Fortran program spans several files, and used to be called as a PROGRAM. What I tried to do was change the main PROGRAM call to a SUBROUTINE called SIMULATOR. Then, I compiled each Fortran source code into an object file without putting them all into an executable. I then got ready to link all the Fortran objects up with a simple C++ wrapper for testing. The code and makefile follow.

wrapper.cpp:

#include <iostream.h>

using namespace std;

extern "C"{
void simulator_();
}

int main()
{
    cout << "starting..." << endl;
    simulator_();
    cout << "success!" << endl;
    return 0;
}

Makefile:

all:
    ifort -nologo -O3 -cxxlib -nofor-main -gen-interfaces -traceback -check bounds -save -static -threads -c modules.for
    ifort -nologo -O3 -cxxlib -nofor-main -gen-interfaces -traceback -check bounds -save -static -threads -c Finterp.for
--a few more sources go here--
    ifort -nologo -O3 -cxxlib -nofor-main -gen-interfaces -traceback -check bounds -save -static -threads -c Simsys.for
    icpc -c wrapper.cpp
    icpc -o cppprogram *.o

Here is (part of) the output from the compiler. Simsys is the file that contains the simulator function I’m trying to call:

Simsys.o: In function `simsys_':
Simsys.for:(.text+0xed4): undefined reference to `for_write_int_lis'
Simsys.for:(.text+0xeef): undefined reference to `for_adjustl'
Simsys.for:(.text+0xf38): undefined reference to `for_trim'
Simsys.for:(.text+0xf83): undefined reference to `for_concat'
Simsys.for:(.text+0x1071): undefined reference to `for_open'
Simsys.for:(.text+0x131d): undefined reference to `for_emit_diagnostic'
Simsys.o:Simsys.for:(.text+0x1670): more undefined references to `for_emit_diagnostic' follow

Now according to a person with a similar problem (http://www.velocityreviews.com/forums/t288905-intel-compiler-8-1-c-calling-fortran-routine.html), it seems like I’m missing some libraries. That person wrote that they included a specific library and it helped them, but I don’t know how to begin to look for what libraries I need. I also don’t know how to find the path of the intel compiler on the HPC system I’m using, so I would appreciate some help looking in the right direction. I didn’t have to do anything special to compile the fortran PROGRAM before I was trying to link it with the C++, so I’m kind of stuck in thinking about where to go from here.

By the way, the Fortran program doesn’t need any inputs, it’s all self-contained.

Thanks in advance for your help and insights!

Edits:

which ifort gave me:
/usr/global/intel/Compiler/11.1/073/bin/intel64/ifort

After trying to do the final link using ifort, I got the following error:

ld: cannot find -lunwind

I found documentation about unwind (https://savannah.nongnu.org/news/?group=libunwind) but I didn’t try to call this library myself and don’t know where this was coming from.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:08:52+00:00Added an answer on June 2, 2026 at 1:08 pm

    The easy way is to use ifort for the linking, to obtain the Fortran runtime libraries. Some instructions are at http://www.ualberta.ca/AICT/RESEARCH/LinuxClusters/doc/ifc91/main_for/mergedProjects/bldaps_for/pgsclmix.htm

    If you use the ISO_C_Binding on the Fortran side you can take control of the name of the routine and get rid of the underscore. Trivial … the ISO C Binding will become much more useful if you start adding arguments between C/C++ and Fortran.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call from my code for some other program . And I
I'm writing code that will call a C function from Fortran using Fortran's C
I'm very very new to Fortran and the whole Intel compiler thing (I'm using
I need to call a library function that sometimes won't terminate within a given
I need to call a number of different procedures within an Oracle package successively
I need to call some methods in Wininet.dll from a Java program. I can
I need to call a c library from my python code. The c library
I need to call a function on a using jquery. This function needs to
I am writing a program in Fortran and I need a way of calculating
I need to call several QWidget.update(rectangle) on the same widget, each time in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.