Q:

Link error when using lex and yacc output in Visual Studio

I am using this windows version of flex (lex) and bison (yacc) to port my query compiler from linux to Windows.
The output files, lex.yy.c, y.tab.c and y.tab.h are getting generated properly.
However, I am getting the following link error.
Error 29 error LNK2001: unresolved external symbol _yylval G:\Project\lex.yy.obj QC
Error 30 error LNK1120: 1 unresolved externals G:\Project\QC.exe QC

I tried copying the above files generated by the original linux versions of flex and yacc to Visual studio project folder. But that too gives the same link error.

A:

This could happen because you're mixing C++ and C files together in one project.  So if you're including y.tab.h into a .cpp file then make sure it has extern "C" { ... } around it.  Like this:
extern "C"
{
    #include "y.tab.h"
}

Update:  From your comment I understood that y.tab.c is y.tab.cc now.  This causes a link time error.  This could be fixed by either making both files C++ (or C).  Or by changing yylval declaration in y.tab.h to
#ifdef __cplusplus
extern "C" YYSTYPE  yylval;
#endif

