Although "Undefined Reference error" questions have been asked several times, I couldn't find solution to my problem.
I am trying to get flex and bison to work in a Qt app. I am facing problem in linking only.
These are the relevant files-
1) icd.l - Lex specification - It generates iclexer.c and contains definition of functions-
void yyerror(char const *s){...}
void* setUpBuffer(char const* text){...}
void tearDownBuffer(void* buffer){...}
int nextToken(){...}
2) iclexer.h
#ifndef ICLEXER_H
#define ICLEXER_H
extern void yyerror(char const *);
extern int yylex();
extern char* yytext;
extern void* setUpBuffer(char const* text);
extern void tearDownBuffer(void* buffer);
extern int nextToken();
#endif // ICLEXER_H
3) icparser.h
#ifndef ICPARSER_H
#define ICPARSER_H
#include "iclexer.h"
#include <string>
extern void initLexer(std::string const& t);
extern void clearLexer();
extern int yyparse();
class Parser
{
public:
Parser(std::string const& s)
{
initLexer(s);
}
void parse()
{
yyparse();
}
~Parser()
{
clearLexer();
}
};
#endif // ICPARSER_H
4) icd.y - Bison specification - It generates icparser.cpp and contains definition of functions-
void initLexer(std::string const& t);
void clearLexer();
int yylex();
In my GUI code I include icparser.h and use class Parser
's interface. But I am getting following error-
/home/vinayak/codes/qt/dic_sim/icparser.cpp:1402:
error: undefined reference to `yyerror(char const*)'
And similar errors for setUpBuffer(char const* text);
, tearDownBuffer(void* buffer);
and nextToken();
. Basically the functions in iclexer.c are not getting linked properly.
Please tell me how to either modify this code or how to change linking order in Qt (Qt Creator)?
extern "C"
around the C declarations? – David Rodríguez - dribeasextern "C"
anywhere. – Vinayak Garg