delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/02/22/00:22:01

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "Steve Baldwin" <stbaldwin AT multiservice DOT com>
To: <cygwin AT cygwin DOT com>
Subject: Accessing global variables causes segfault
Date: Sat, 22 Feb 2003 16:21:33 +1100
Message-ID: <000701c2da32$4472f640$3264a8c0@AUSTBMOBILE>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

I'm having some (further) issues porting some Unix code to cygwin.  I
have a
scenario where there are global variables defined in a shared library,
and referenced in the executable.  See the example below.  Yes I know
it's bad coding practice, but I'm hoping to port the code with the least
amount of re-writing as possible.  It works fine under Unix, but as you
can see from below, doesn't play well under cygwin.  Is there anything
I can do - apart from the obvious re-write.

Cheers,

Steve

[cdev]$ cat a.c
#include <stdio.h>
#include <stdlib.h>
extern void fx (void) ;
extern int myglobal ;

int
main (int argc, char **argv) {
        myglobal = 99 ;
        fx () ;
}
[cdev]$ cat b.c
#include <stdio.h>

int             *myglobal ;

void
fx (void)
{
        printf("here i am : myglobal = %d\n", myglobal) ;
}
[cdev]$ gcc b.c -o libb.dll -shared
[cdev]$ gcc a.c -o a -L. -lb
[cdev]$ a
Segmentation fault (core dumped)


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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