I'm having trouble with compiling a piece of code I have been given for my research. It consists of one component written in C++ and the other in FORTRAN. I think the problem is to do with my gcc version.
The first file for example is a C++ file (foo.ccp)
#include <iostream>
using namespace std;
extern "C" {
extern int MAIN__();
}
int main(){
cout << "main in C++\n";
return MAIN__();
}
The second is bar.f90:
program test
implicit none
print*, 'MAIN in FORTRAN'
end program test
I'm trying to compile it like so:
g++ -c foo.cpp
gfortran foo.o -lstdc++ bar.f90
It compiles fine with GCC-4.4.7 but fails with GCC-4.8.x with the error reading:
/tmp/cc5xIAFq.o: In function `main':
bar.f90:(.text+0x6d): multiple definition of `main'
foo.o:foo.cpp:(.text+0x0): first defined here
foo.o: In function `main':
foo.cpp:(.text+0x14): undefined reference to `MAIN__'
collect2: error: ld returned 1 exit status
I've read here that there's a change in how gfortran handles naming of the 'main' and 'MAIN__' functions since version 4.5.x but I'm not sure how to fix my problem.
Any ideas as to what I'm missing? Thanks for your help!