Subject: Re: compilation of statist under cygwin

From: [email-masked]
Date: Mon, 29 Mar 2004 12:43:33 +0200 (MEST)

Hi Andreas and Bernhard,

thanks for your replies. With your suggestions, I managed to compile
statist; however, about 200 warnings were issued similar to
"plot.c:434: warning: passing arg 1 of `out_err' makes pointer from integer
without a cast"

And, even worse, the program now crashes each time I try to read in some
data.

Stefan

> GNU lib-C doc says, that errno is defined in errno.h:
>
http://www.gnu.org/software/libc/manual/html_node/Checking-for-Errors.html#Checking%20for%20Errors
> 
> errno.h is not explicitely included in statist.h, where errno is used. 
> Apparently this bug remained undetected, because errno.h gets included 
> by other header files on other platforms.
> Add the line
> #include <errno.h>
> at the beginning of statist.h and iodefs.c. Does that help?
> 
> 	Andreas
> 
> [email-masked] wrote:
> 
> > Hello all,
> > 
> > I am having problems to compile statist (v1.0.1) under cygwin, please
> see
> > the error messages below. The same error messages occur also with the
> -DMSDOS
> > flag. Can anybody help?
> > 
> > Best regards,
> > Stefan
> > 
> > 
> > [fronzek@KK450 ...statist/src]$ gcc -v
> > Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/specs
> > gcc version 2.95.3-5 (cygwin special)
> > 
> > [fronzek@KK450 ...statist/src]$ make
> > gcc -c -Wall  -DNO_GETTEXT -DLANG=LANG_EN  statist.c
> > gcc -c -Wall  -DNO_GETTEXT -DLANG=LANG_EN  menue.c
> > gcc -c -Wall  -DNO_GETTEXT -DLANG=LANG_EN  procs.c
> > gcc -c -Wall  -DNO_GETTEXT -DLANG=LANG_EN  funcs.c
> > gcc -c -Wall  -DNO_GETTEXT -DLANG=LANG_EN  data.c
> > gcc -c -Wall  -DNO_GETTEXT -DLANG=LANG_EN  plot.c
> > gcc -c -Wall  -DNO_GETTEXT -DLANG=LANG_EN    -c -o memory_handling.o
> > memory_handling.c
> > gcc -o statist statist.o menue.o procs.o funcs.o data.o plot.o
> > memory_handling.o
> >  -lm
> > statist.o(.text+0x59b):statist.c: undefined reference to `errno'
> > statist.o(.text+0x753):statist.c: undefined reference to `errno'
> > menue.o(.text+0x410c):menue.c: undefined reference to `errno'
> > menue.o(.text+0x4238):menue.c: undefined reference to `errno'
> > menue.o(.text+0x495a):menue.c: undefined reference to `errno'
> > menue.o(.text+0x4aef):menue.c: more undefined references to `errno'
> follow
> > collect2: ld returned 1 exit status
> > make: *** [statist] Error 1

-- 
+++ NEU bei GMX und erstmalig in Deutschland: TÜV-geprüfter Virenschutz +++
100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz

---

From: Bernhard Reiter <[email-masked]>
Date: Mon, 29 Mar 2004 13:01:45 +0200

> Hi Andreas and Bernhard,

Andreas: 
Why didn't I see your reply on the list? :)
	Bernhard

---

From: Bernhard Reiter <[email-masked]>
Date: Mon, 29 Mar 2004 13:17:12 +0200

On Mon, Mar 29, 2004 at 12:43:33PM +0200, [email-masked] wrote:
> statist; 

> however, about 200 warnings were issued similar to

Arg.
Seems like there is an errno name clash.
Try shifting the #include <errno.h> line
directly in front of 
	extern int errno;
in statist.h

	Bernhard

---

From: Bernhard Reiter <[email-masked]>
Date: Mon, 29 Mar 2004 13:26:21 +0200

> Try shifting the #include <errno.h> line

That is not enough, try the following patch against
a fresh 1.0.1.

Patch to resolve errno name clash issues.
	[email-masked]

===================================================================
RCS file: /statistrepository/statist/CHANGES,v
retrieving revision 1.3
diff -u -r1.3 CHANGES
--- CHANGES	13 Jun 2003 13:40:35 -0000	1.3
+++ CHANGES	29 Mar 2004 11:23:49 -0000
@@ -1,4 +1,7 @@
 Changes up to 
+	* Resolved name clash with our_err errno, 
+	discovered by Stefan Fronzek trying to compile on Cygwin.
+
 	* added hint for compilation with MinGW (Thanks to Andreas Beyer).
 
 Changes up to v1.0.1: Bernhard Reiter <[email-masked]>
Index: src/statist.c
===================================================================
RCS file: /statistrepository/statist/src/statist.c,v
retrieving revision 1.6
diff -u -r1.6 statist.c
--- src/statist.c	15 Nov 2001 20:28:55 -0000	1.6
+++ src/statist.c	29 Mar 2004 11:23:49 -0000
@@ -293,13 +293,12 @@

-void out_err(int errno, char *modulname, int lno, char *fmt, ...) {
+void out_err(int errn, char *modulname, int lno, char *fmt, ...) {
   va_list argptr;
-  int error;
   char where[128];
 
   va_start(argptr, fmt);
-  switch (errno) {
+  switch (errn) {
     case WAR: strcpy(line, 
     		_("> statist-warning ",
 		  "> statist-Warnung ") );
@@ -322,7 +321,6 @@
       break;
   }
 
-  error = errno;
   if (lno != 0) {
     sprintf(where, 
     		_("(Modul %15s, line %i):\n  ",
@@ -340,12 +338,12 @@
     strncat(line, "\a\n\n", 254-strlen(line));
   }
   vfprintf(stderr, line, argptr);
-  if ( ((errno==MAT) || (errno==MWA)) && (log_set) ) {
+  if ( ((errn==MAT) || (errn==MWA)) && (log_set) ) {
     vfprintf(logfile, line, argptr);
   }
   va_end(argptr);
 
-  if (error == FAT) {
+  if (errn == FAT) {
     finish();
     exit(1);
   }
Index: src/statist.h
===================================================================
RCS file: /statistrepository/statist/src/statist.h,v
retrieving revision 1.12
diff -u -r1.12 statist.h
--- src/statist.h	13 Jun 2003 13:40:36 -0000	1.12
+++ src/statist.h	29 Mar 2004 11:23:49 -0000
@@ -109,9 +109,9 @@
 
 #ifdef SUNOS
 extern char *sys_errlist[];
-#define STRERROR(errno) sys_errlist[errno]
+#define STRERROR(errn) sys_errlist[errn]
 #else
-#define STRERROR(errno) strerror(errno)
+#define STRERROR(errn) strerror(errn)
 #endif
 
 #ifdef DEBUG
@@ -240,6 +240,7 @@
 } SORTREC;

+#include <errno.h>
 extern int errno;
 extern void mywait();
 extern BOOLEAN myexist(char *name);
@@ -252,7 +253,7 @@
 #endif
 extern void out_d(char *fmt, ...);
 extern void out_r(char *fmt, ...);
-extern void out_err(int errno, char *modul, int lno, char *fmt, ...);
+extern void out_err(int errn, char *modul, int lno, char *fmt, ...);
 extern void print_histo(REAL x[], int y[], int n);
 extern void finish();

---

From: [email-masked]
Date: Mon, 29 Mar 2004 13:46:47 +0200 (MEST)

I moved the "extern int errno;" to the beginning of statist.h directly
behind "#include <errno.h>" and now it seems to work. The compiler warnings have
not disappeared, but the resulting executable seems to work correctly.

Thanks a lot for your help,
best regards,
Stefan

---

From: Bernhard Reiter <[email-masked]>
Date: Mon, 29 Mar 2004 14:40:23 +0200

> not disappeared, but the resulting executable seems to work correctly.

Can you also try the patch?

The confirmation would be nice,
then I know for sure that the patch solves the problems.

	Bernhard

---

From: Bernhard Reiter <[email-masked]>
Date: Tue, 30 Mar 2004 12:05:20 +0200

On Tue, Mar 30, 2004 at 11:08:57AM +0200, [email-masked] wrote:
> I tried with renaming all "errno" to "errno2" in all files (that's what you
> have done in your patch, isn't it?), 

No, I have only renamed the ones for the macro
and the out_err function.
It should be easier to just
untar 1.0.1 again and use the "patch" command

cd statist-1.0.1
	patch -d .  < patch.diff
	
on the file I have attached.

> but it didn't solve the problem.

---

From: [email-masked]
Date: Fri, 2 Apr 2004 08:22:41 +0200 (MEST)

Hi Bernhard,

sorry for the long response time.
Yes, your patch did the trick. The compiler gave no more warnings and
statist works fine.

Best regards,
Stefan

---

From: Bernhard Reiter <[email-masked]>
Date: Fri, 2 Apr 2004 11:10:08 +0200

> Yes, your patch did the trick. The compiler gave no more warnings and

Stefan:
Thanks for finding the bug and testing the solution!

The patch is also commited to CVS.
There is one more thing I like to add before
releasing a new tarball and that would be 
gettext language support.

	Bernhard