delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/01/18/23:47:31

From: khan AT xraylith DOT wisc DOT edu (Mumit Khan)
Subject: Re: G77 fork problems
18 Jan 1999 23:47:31 -0800 :
Message-ID: <199901182352.RAA21811.cygnus.gnu-win32@modi.xraylith.wisc.edu>
References: <36A37EBC DOT C60EF81D AT inspirepharm DOT com>
To: ssiddiqi AT ipass DOT net
Cc: gnu-win32 AT cygnus DOT com, egcs-bugs AT cygnus DOT com

"Suhaib M. Siddiqi" <ssiddiqi AT inspirepharm DOT com> 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
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019