5

I am going to port the C project that was for unix into windows. So far, I could make it compile but not build . The problem I am getting is , some of the functions which are declared in the header files are defined in the yacc files.so I am getting the following errors:

 error LNK2001: unresolved external symbol function_name

I am adding .y and .l files in the source directory of the project.I think I could not port yacc files into windows version or am I doing something stupid.I search it on web but could not get proper tutorial for it.Could you please let me know

  1. How could I add .y or .l files in the project.
  2. How would I make those file compatible to the windows?
  3. How can I link them with other object files.

EDIT

I tried with changing the the .l files into the .yy.c files using the flex.exe.Following is the command for it

     c:\> flex.exe name.l

Supposing that both the flex.exe and name.l are in C;>.And I loaded those all those files .l .y(previously present for parsing in unix system) .yy.c(corrsonding yacc file for windows) in the solution of previously exisiting project. Once I compile,I get the following

 Can't read the header file  parserheaderfile.h 

This is the header file which needs to be generated by the bison in the unix system. So I think I am not able to make the bison compatible for windows .So please him me how can I solve this problem?

Thanks in advance.

thetna
  • 6,903
  • 26
  • 79
  • 113

1 Answers1

9

You need to add custom build rules for your .y and .l files. To do this, you need to

  1. create one dummy .c file for the .l file and the .y file
  2. add the .l, .y and both .c files to the project
  3. right click on the .l file and select properties
  4. Configuration->All Configurations
  5. General->Item Type->Custom Build Tool
  6. Apply
  7. Custom Build Tool->General->Command Line->flex -olexer.c lexer.l
  8. Custom Build Tool->General->Outputs->lexer.c
  9. Custom Build Tool->General->Additional Dependencies->parser.y parser.c
  10. Apply
  11. select the .y file in the solution explorer
  12. Configuration->All Configurations
  13. General->Item Type->Custom Build Tool
  14. Apply
  15. Custom Build Tool->General->Command Line->bison -oparser.c parser.y
  16. Custom Build Tool->General->Outputs->parser.c parser.h

Also you need to have flex.exe, bison.exe and m4.exe in the system search path. Another drawback is that VS does not get the dependencies right, so when you change something in the parser or lexer files, you need to manually rebuild the project.

Rudi
  • 19,366
  • 3
  • 55
  • 77
  • Is this something you have to set each time you start up a new project using f/lex and/or bison/yacc? Or can you set it once and VS will remember the settings forever and ever and ever? Also, are there any recommended IDEs for using those libraries? Doing things from the command line can sometimes be annoying when you have to run f/lex and/or bison/yacc before you can compile with gcc. – velocirabbit Oct 31 '16 at 02:31
  • 1
    @velocirabbit This is a project specific setting. So you need to configure it for each .l or .y file. – Rudi Oct 31 '16 at 09:10