Linking C++ into a Fortran program is next to impossible because of the name mangling unless everything lives inside an extern "C". Alternatively, you could make the interface extern "C" and the implementation C++.
This is how to link an existing Fortran library with a C++ program which is what the other article is about.
1) Create a Fortran subprogram, say worker.for. This is F77 so remember the 6 leading spaces
subroutine printhi
print *, 'it works'
end subroutine
2) Create a C++ program that calls it, say boss.cpp. Note trailing underscore in the Fortran routine name
#include <iostream>
// Avoid any name mangling
extern "C"
{
extern void __attribute__((stdcall)) printhi_(void);
}
int main()
{
std::cout << "Calling fortran" << std::endl;
printhi_();
std::cout << "Returned to C++" << std::endl;
}
3) Build the F77 routine
gfortran -c worker.for
4) Build and link the C++ program. Add the fortran library to resolve any fortran specific bits.
g++ boss.cpp worker.o -o cboss -L/usr/lib -lgfortran
5) Run the program
./a.out