I'm trying to verify a a simple hello world function written in c++ can be called from a FORTRAN script (gfortran 4.9.20. I have little experience with both c++ and FORTRAN so I thought this is were I should start.
//code.cpp
#include <iostream>
extern "C"
{
void worker();
int main()
{
worker();
}
void worker()
{
std::cout << "Hello, World!\n";
}
}
and a header as follows
//code.h
#include "code.cpp"
extern "C"
{
void worker();
}
I was able to call my hello function in c++ with the simple code below
//readheader.cpp
#include "code.h"
extern "C"
{
void worker();
}
I thought all was well until I attempted to read the same code using FORTRAN. It could be my compile line and at this point I'm not sure which part of my code is broken. Below is my FORTRAN Code
c codeF.f
program main
include 'code.h'
print *, 'Calling C'
call worker()
print *, 'Back to F77'
end program main
my compile script
gfortran -I/Path/to/file -c codeF.f
where I get about 8 errors with the 'code.h' header. Although my c++ code can read the header FORTRAN can not. All my internet research so far has lead me here in hopes someone with experience could help me out.
Thanks