I am trying to compile some C-code (written in 1993) and ironed out a few minor wrinkles but am stuck at one (15/16 objects compiled with 2 minor tweaks). Here's the code sending me an error:
#include "diagmesg.h"
#include <string.h>
#include <stdlib.h>
/* Definition of global variables */
FILE * error_fp = stderr;
Here's diagmesg.h:
#ifndef DIAGMESG_H
#define DIAGMESG_H
#include <stdio.h>
/* extern int fprintf(); CHANGE 9/3 */
/* Global types */
/* Possible settings for the Diagnostic Reporting Level */
enum Diagnostic_Level { NONE, ERROR, INFORM, DEBUG };
/* Declaration of global variables */
extern enum Diagnostic_Level current_level;
extern FILE *error_fp;
/* macros for doing Diagnostic Report */
#define ERROR_MSG( s )\
do{ if ( current_level >= ERROR ) fprintf( error_fp, "(e) %s\n", s); }while(0)
#define INFORM_MSG( s )\
do{ if ( current_level >= INFORM ) fprintf( error_fp, "(i) %s\n", s); }while(0)
#define DEBUG_MSG( s )\
do{ if ( current_level >= DEBUG ) fprintf( error_fp, "(d) %s\n", s); }while(0)
/* buffer control */
#define BUFFER_BLOCK 32
extern void Buffer_MSG( enum Diagnostic_Level, char *);
extern void Flush_MSG( void );
#endif
Here's the (relevant) message from the compiler:
GNU C (GCC) version 4.5.3 (i686-pc-cygwin)
compiled by GNU C version 4.5.3, GMP version 4.3.2, MPFR version 3.0.1-p4, MPC version 0.8
warning: MPFR header version 3.0.1-p4 differs from library version 3.1.2.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129520
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/include"
ignoring duplicate directory "/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include-fixed
/usr/include
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api
End of search list.
GNU C (GCC) version 4.5.3 (i686-pc-cygwin)
compiled by GNU C version 4.5.3, GMP version 4.3.2, MPFR version 3.0.1-p4, MPC version 0.8
warning: MPFR header version 3.0.1-p4 differs from library version 3.1.2.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129520
Compiler executable checksum: 89d6774c1d510265da7d48b735ce61fb
diagmesg.c:17:1: error: initializer element is not constant
Makefile:101: recipe for target `diagmesg.o' failed
make: *** [diagmesg.o] Error 1
Line 17 in the source is the FILE * error_fp = stderr;
statement shown above
I am not a routine C programmer. If anyone can clarify what "initializer element is not constant" means and/or a possible solution to compile would be very thankful.
This is an issue with the system library.The file provided by the system library is providing a definition of stderr which is not a constant.
Earlier (i mean in old libraries) stderr was given as #define stderr _IO_stderr
and now it is extern FILE *stderr
.
There is already some workaround exists like using custom stdio.h.For more info refer this.