I am currently getting the error message:
In file included from /usr/include/errno.h:35:0,
from lex.yy.c:21:
/usr/include/x86_64-linux-gnu/bits/errno.h:50:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’
extern int *__errno_location (void) __THROW __attribute__ ((__const__));
^
(along with many others) when attempting a to compile a file generated by lex using the command:
gcc lex.yy.c
lex.l (file passed to lex to generate lex.yy.c) source:
%%
"hello world" printf("goodbye");
. ;
%%
This problem occurs when I try to compile any file which has been generated by lex or flex (I've tried both)
As I mentioned there are also many more errors but maybe fixing this one will solve some of the others. After looking for some common errors with errno.h and finding nothing of any use, I'm asking here.
I am using Ubuntu 16.04 LTS. Let me know if you would like/need more information regarding the problem and I'll do my best to help.
Thanks for any advice :)
Edit for 'rici':
The first 21 lines of my lex.yy.c file are as follows:
#line 3 "lex.yy.c"
#define YY_INT_ALIGNED short int
/* A lexical scanner generated by flex */
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
#define YY_FLEX_SUBMINOR_VERSION 0
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
/* end standard C headers. */
Edit for @sepp2k:
I used vimdiff to compare the 2 files.
Things that are in my file but aren't in yours:
#ifdef __cplusplus
/* The "const" storage-class-modifier is valid. */
#define YY_USE_CONST
#else /* ! __cplusplus */
/* C99 requires __STDC__ to be defined as 1. */
#if defined (__STDC__)
#define YY_USE_CONST
#endif /* defined (__STDC__) */
#endif /* ! __cplusplus */
#ifdef YY_USE_CONST
===============================================================
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#line 476 "lex.yy.c"
There is nothing really which is in your file that is not in mine
Any other differences seem to just be differences of formatting.
I also tested the four header files in a standard C program (see what you mean now) and I can confirm it is errno.h which is causing the error.
A hello world in C with errno.h included threw up the following error:
In file included from /usr/include/errno.h:35:0,
from test.c:2:
/usr/include/x86_64-linux-gnu/bits/errno.h:50:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’
extern int *__errno_location (void) __THROW __attribute__ ((__const__));
^
In file included from test.c:4:0:
/usr/include/stdio.h:13:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
int printf(const char* __restrict, ...);
^
edit for @rici:
Here is the full dump of errors thrown when i run "gcc lex.yy.c": https://gist.github.com/raygarner/0601e57f5be21e16e0ae4ee34643b121
edit for @sepp2k:
earlier on, i tested this exact same compilation process on a fresh install of debian 9 in a VM and I got the exact same error I am doing here, on Ubuntu after fixing errno.h
Here is what it looks like:
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
gcc -c. Are those the exact contents of your lex file? Can you show us what the generated lex.yy.c looks like? Can you compile a normal C program like hello world? - sepp2k