C + FORTRAN + getenv() (Was: NCAR running under AIX 3.1 update 3003)

C + FORTRAN + getenv() (Was: NCAR running under AIX 3.1 update 3003)

Post by Scott Ho » Fri, 19 Apr 1991 06:01:28




Quote:

>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.

Georgia Tech                            UUCP: ..!gatech!prism!scott
Office of Information Technology, Technical Services

 
 
 

C + FORTRAN + getenv() (Was: NCAR running under AIX 3.1 update 3003)

Post by Gary Kaka » Fri, 19 Apr 1991 04:25:57


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);

Quote:}


 
 
 

C + FORTRAN + getenv() (Was: NCAR running under AIX 3.1 update 3003)

Post by hobe.. » Mon, 22 Apr 1991 08:34:36



Quote:> 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

 [....]

yep ! it does crash. I discovered this problem when I rebuilt the VOGLE
library. Turns out that this bug (?) got introduced, after we applied the most
recent update of the operating system (3.1.0003). Older EXECUTABLES function ok
but relinking with the older version of the library crashes the programs.
xde traces the problem to the call to getenv. Only mixing C code with FORTRAN
crashes the programs.

Here is the bit of code with the error message from xde:

-----X-----X-----

char path[120], *flib;

 if ((flib = getenv("VFONTLIB")) == (char *)NULL) {
  strcpy(path, FONTLIB);
  strcat(path, fontname);
 } else {
  strcpy(path, flib);
.....

segmentation violation in move._move at 0x10003d34
0x10003d34 (_move+0xec) 7d00052a       stsx   r8,r0,r0
[using soft_stat.char]

----X-----X

Lucky us that we saved all our earlier executables !!!
sigh!

Himanshu.

 
 
 

1. NCAR running under AIX 3.1 update 3003

I remember seeing a note a couple of weeks ago about NCAR breaking when
someone updated to 3003.  Unfortunately, I didn't keep the note, and I
haven't seen any responses.  Can anyone out there tell me if this is
indeed the case?  If so, is there any patch to get it running?

Thanks,
Gary

2. anyone have ppp-2.1.2a working?

3. perl 4.010 under AIX 3.1 (3003) and AIX 3.1.5

4. X11 problem when I turn X off.

5. X11R4 clients on AIX 3.1 (3003+) server

6. How to achieve IPSec in a Solaris 7?

7. problems with 3003 --- NCAR graphics

8. I have a license but the program denies this

9. Bug/Feature of Fortran under 3003?

10. What breaks in 3003 update?

11. cu works but tip doesn't (RS/6000 AIX 3003)

12. Binding in Fortran runtime on AIX 3.1

13. I am missing something important while porting to AIX 3.1?