Error '' unistd.h ': No such file or directory "with flex

1

After creating the .l file, placing the necessary flex commands on the Visual Studio prompt always gives this error. I have already tried to put the mentioned library in the directory but the problem remains.

Error:

Microsoft (R) C/C++ Optimizing Compiler Versão 19.11.25547 para x86
Copyright (C) Microsoft Corporation. Todos os direitos reservados.

lex.yy.c
lex.yy.c(397): warning C4005: 'yywrap': redefinição de macro
lex.yy.c(73): note: consulte a definição anterior de 'yywrap'
calcula.l(5): fatal error C1083: Não é possível abrir arquivo incluir: 'unistd.h': No such file or directory

File code .l :

%option main
%x COMENT
%%
"//"              BEGIN( COMENT );
.|\n|\r
<COMENT>.         ECHO;
<COMENT>\n|\r     BEGIN( INITIAL ); 
%%
    
asked by anonymous 03.01.2018 / 17:46

1 answer

1

unistd.h does not exist in VS, it is usually necessary to add something like cygwin or GnuWin32, but the case is not the VS but the win_flex that is generating the files, so adding something like cygwin or GnuWin32 is unnecessary.

In order for flex to not add dependencies not supported by Windows, or better for the flex application to be compatible with Windows use the --wincompat parameter, like this:

win_flex --wincompat foo.l

There is also the --nounistd parameter, but I think this is specifically to remove the unistd.h from the C script that will be generated, in which case I think --wincompat should set more interesting things for Windows.     

04.01.2018 / 02:32