hello
I created a c static library with this code:
fileopen.h:
extern FILE *fp;
r.h:
#ifdef HAVE_F77_UNDERSCORE
# define F77_CALL(x) x ## _
#else
# define F77_CALL(x) x
#endif
#define F77_NAME(x) F77_CALL(x)
#define F77_SUB(x) F77_CALL(x)
#define F77_COM(x) F77_CALL(x)
#define F77_COMDECL(x) F77_CALL(x)
ex.c:
#include "fileopen.h"
#include "r.h"
static int jacsng = -1;
static int jacupd = -1;
static double jacond = 0.0;
/*
* output for a single incorrect jacobian entry
*/
void F77_SUB(fileopenclose)()
{
fp=fopen("nleqslv.err", "w+");
}
void F77_SUB(nwckot)(int *i, int *j, double *aij, double *wi)
{
fprintf(fp,"Chkjac possible error in jacobian[%d,%d] = %20.13e\n"
" Estimated[%d,%d] = %20.13e\n", *i, *j, *aij, *i, *j, *wi);
}
the library is called test.lib and is linked with this fortran code:
MODULE INTER
interface
SUBROUTINE nwckot(i,j,a,b) BIND(C,name='nwckot')
use, intrinsic :: ISO_C_BINDING
integer (C_INT), value :: i
integer (C_INT) :: j
REAL(C_DOUBLE) :: a
REAL(C_DOUBLE) :: b
end SUBROUTINE nwckot
end interface
interface
subroutine fileopenclose() BIND(C,name='fileopenclose')
use, intrinsic :: ISO_C_BINDING
END subroutine fileopenclose
end interface
END MODULE INTER
SUBROUTINE user
USE INTER
INTEGER i,j
DOUBLE PRECISION a,b
CALL fileopenclose()
CALL nwckot(1,2,1.d0,1.d0)
END SUBROUTINE USER
This last sub is called in the main code that I don't show here.
when I run the app I get an access violation error(157) and I know that it is reated with the fprintf code. But why do I get that error?
I am just starting to mixing languages and this is just me trying to learn, step by step, because I have to build a huge app in fortran that uses a lot of c files that I have to turn into a static library to be called inside my code.
thanks in advance
Peter