I have done some searching online but I cannot find out how to compile a simple C++ and Fortran code from linux. I need to get complex with it, but I just need to know how to start with a simple example.
My C++ code is this:
#include <iostream>
using namespace std;
extern int Add( int *, int * );
extern int Multiply( int *, int * );
int main()
{
int a,b,c;
cout << "Enter 2 values: ";
cin >> a >> b;
c = Add(&a,&b);
cout << a << " + " << b << " = " << c << endl;
c = Multiply(&a,&b);
cout << a << " * " << b << " = " << c << endl;
return 0;
}
My Fortran Code is this:
integer function Add(a,b)
integer a,b
Add = a+b
return
end
integer function Multiply(a,b)
integer a,b
Multiply = a*b
return
end
I am using ifort
to compile my Fortran code and g++ for C++ code. I have tried this terminal command:
$ ifort -c Program.f90
$ g++ -o Main.cpp Program.o
But the error I am getting says "linker input file unused because linking not done."
I am not sure how to link the two together. If someone could please help me out I would greatly appreciate it!
PS - I have tried adding -lg2c
at the end of my compilation line, and it is not recognized.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…