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

Asked

Viewed 330 times

1

After creating the file .l, put the necessary flex command on the command line of Visual Studio always gives this error. I 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 ); 
%%
  • You set the entire text to link to the image on purpose?

  • It was not purposeful. I am new here.

  • I’m sorry, I’ve changed

  • No, the project is provided by the teacher. A simple example of a compiler that should accept comments in C++.

  • I think I understand the flex now, but it’s strange that it uses unistd. h, try to use the parameter --wincompat or you may have to install Cygwin or gnuwin32

  • I don’t know if you couldn’t explain it to me. I’ll do it again: The goal is to create a file (txt type) in the format .l and make it work as a compiler. By developing the visual studio by calling the flex tool with the command win_flex aaa.l,for example by following the command cl lex.yy.c and having the lex.yy. And right now, in the developer, you should only play something in comment form. In my case, I can put the command cl lex.yy.c, he creates lex.yy.obj but then when placing lex.yy gives the mentioned error

  • in the win_flex adds the parameter --wincompat as I said in the previous comment, so for example win_flex --wincompat aaa.l

  • It already works with this parameter. Thanks for the help.

Show 3 more comments

1 answer

1


The unistd.h does not exist in VS, it is usually necessary to add something like Cygwin or Gnuwin32, but the case is not quite the VS but the win_flex which is generating the files, so adding something like Cygwin or Gnuwin32 is unnecessary.

So that flex does not add dependencies not supported by Windows, or better so that the flex application is compatible with Windows use the parameter --wincompat, thus:

win_flex --wincompat foo.l

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.