Subject: Re: G77 fork problems
From: [email-masked] (Mumit Khan)

18 Jan 1999 23:47:31 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
To: [email-masked]
Cc: [email-masked], [email-masked]

"Suhaib M. Siddiqi" <[email-masked]> writes:
> Has anyone any suggestions why G77 (EGCS-1.1.1) gives undefined
> refernece to fork_.  I get same problem on RedHat Linux 5.2 with
> EGCS-1.1.1 and Cygnus-B20 with EGCS-1.1.1.
> 
> gridu.f: undefined reference to `fork_'
> collect2: ld returned 1 exit status.

You have to write a "wrapper" function callable from g77. Take a look at
the files in libf2c/libU77 (in egcs-1.1.1 source code) on how to do this.

Here's a start. Note that it's completely untested -- the includes I've
used (eg., unistd.h) may not even exist on your system, pid_t may not be 
the same as g77 "integer" type, etc etc.
 
  /* g77fork.c -- simple fork wrapper for g77 on systems that support
     fork.  */
  #include <unistd.h>
  #include <g2c.h>

  static integer
  G77_fork_0 (void)
  {
    return fork ();
  }

  int
  fork_ (void)
  {
    return G77_fork_0 ();
  }

Here's a trivial test program (nope, I didn't run it, so don't know if
it'll even compile):

c
c     forktest.f
c
      program forktest
      external fork, getpid
      integer fork, pid, getpid
c
      write (*,*) 'parent pid = ', getpid ()
      pid = fork ()
      if (pid .eq. 0) then
        write (*,*) 'Child process. Child pid = ', getpid ()
      else
        write (*,*) 'Parent process. pid = ', pid
      end if
      call exit (0)
      end

Now you should be able to do the following:
  
  $ g77 -o forktest forktest.f g77fork.c 

Regards,
Mumit

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".