Reputation: 197
I have a library written in C/C++ which is declared, by its developers, to have a Fortran interface. The interface would be enabled including a header file *.h and calling a classical subroutine. I would like to compile my Fortran program linking also that library. The library has been tested already and it works.
Here it is the main program:
! Main program
INCLUDE 'pastix_fortran.h'
Program TEST
IMPLICIT NONE
call GO_PASTIX
END PROGRAM TEST
The routine GO_PASTIX is
SUBROUTINE GO_PASTIX
IMPLICIT NONE
pastix_data_ptr_t :: pastix_data
integer :: pastix_comm
pastix_int_t :: n, rhs, ia(NCOLS+1), ja(NNZER)
pastix_float_t :: avals(NNZER), b(NROWS)
pastix_int_t :: perm(NROWS), invp(NROWS), iparm(64)
real*8 :: dparm(64)
call pastix_fortran(pastix_data,pastix_comm,n,ia,ja,avals,perm,invp,b,rhs,iparm,dparm)
END SUBROUTINE
Whereas in the file pastix_fortran.h the types of variables used in the subroutine are defined:
#define PASTIX_INT_KIND 4
#define pastix_int_t INTEGER(kind=4)
#define pastix_uint_t unsigned INTEGER(kind=4)
#define pastix_data_ptr_t INTEGER(kind=4)
#define MPI_PASTIX_INT MPI_INTEGER4
#define pastix_float_t REAL(kind=8)
#define MPI_PASTIX_FLOAT MPI_REAL8
Using VS2010 I added the option to preprocess file with /fpp and I did not forgot to add all include directories and files. However the compiler says that:
for the header lines: "Warning 1 warning #5117: Bad # preprocessor line"
for the fortran subroutine: "error #6404: This name does not have a type, and must have an explicit type. [PASTIX_DATA_PTR_T]" and so on for the rest of the variables...
How can I work out this?
Upvotes: 4
Views: 6079
Reputation: 78316
This line
#define pastix_uint_t unsigned INTEGER(kind=4)
is going to cause most Fortran compilers a wee problem since the language has never supported unsigned integers using this or any other syntax. Some deviant implementations may have supported them, but they are definitely not standard.
Upvotes: 3
Reputation: 3812
Apparently, the #define
for the type is not correctly processed. I think, one of the possible problems is the way you include the header file in Fortran, as you are doing it via a Fortran statement instead of a preprocessor directive. So, probably it is only included, after the file had been already preprocessed. Therefore, the #define
options in the .h file are not resolved by the preprocessor.
Changing the include()
statement into an #include
preprocessor directive may solve the problem.
Upvotes: 4