kakazu@theory.tn.cornell.edu (Gary Kakazu) (04/18/91)
Last week I asked about running NCARG under AIX 3.1 update 3003. I
heard that there were some troubles running ncarg under 3003. Some
of the responses I got said that it would run, and some said wouldn't.
I decided to try it myself and found the following problem.
It appears that if a Fortran program calls a C program, and the C
program calls the routine getenv, the program crashes. If I comment
out getenv in the routines that call it, and pass the GRAPHCAP & FONTCAP
info on the command line, the example program works fine.
If you just have a C program that calls getenv, it works fine.
I have written an example of a C & Fortran program that illustrates
the problem. If anyone knows of a way around this, let me know.
Thanks.
----------The Makefile-----------------
COBJS = test1.o
FOBJS = test1f.o
FFLAGS = -g
test1: $(COBJS) $(FOBJS)
xlf $(FFLAGS) -o test1 $(COBJS) $(FOBJS)
--------Call me test1f.f---------------------
call c_routine( )
stop
end
--------Call me test1.c-----------------
c_routine( )
{
char *ptr;
printf("Before getenv\n");
ptr = getenv( "PWD" );
printf("ptr is: %s\n",ptr);
}
scott@prism.gatech.EDU (Scott Holt) (04/18/91)
In article <1991Apr17.192557.5133@batcomputer.tn.cornell.edu> kakazu@theory.tn.cornell.edu (Gary Kakazu) writes: > >It appears that if a Fortran program calls a C program, and the C >program calls the routine getenv, the program crashes. If I comment >out getenv in the routines that call it, and pass the GRAPHCAP & FONTCAP >info on the command line, the example program works fine. > You are essentially correct - there is a problem. However, it is possible to mix FORTRAN and C with a C routine that calls getenv - just make sure you link in the C runtime library... as in: test1: $(COBJS) $(FOBJS) xlf $(FFLAGS) -o test1 $(COBJS) $(FOBJS) -lc Ordinarily the linker will satisfy the reference to getenv from the FORTRAN runtime library. Now, there is a problem if BOTH the FORTRAN and C routines call their respective getenvs - There can only be one getenv symbol in the final bound product so someone looses. -Scott -- This is my signature. There are many like it, but this one is mine. Scott Holt Internet: scott@prism.gatech.edu Georgia Tech UUCP: ..!gatech!prism!scott Office of Information Technology, Technical Services