I am writing an SQL parser. SQLSelectParser.l
is the lex file which generates lex.yy.c
file successfully using lex compiler. In SQLSelectParser.l
file, I call external functions defined in Ast.h/c
file. I #include Ast.h in %{ %} section of SQLSelectParser.l
.
I compiles the src file individually without any problems.
lex SQLSelectParser.l
gcc -g -c lex.yy.c -o lex.yy.o
gcc -g -c Ast.c -o Ast.o
gcc -g lex.yy.o Ast.o -o exe -lfl << but get linker error.
Function ast_add_child
is declared in Ast.h and defined in Ast.c. I am not able to understand why i am getting linker error. Is this common problem while linking with flex generated src file ?
/usr/bin/ld: lex.yy.o: in function `create_q_parse_columns':
/home/vm/RDBMSImplementation/Parsers/SQLSelectParser.l:405: undefined reference to `ast_add_child'
/usr/bin/ld: /home/vm/RDBMSImplementation/Parsers/SQLSelectParser.l:417: undefined reference to `ast_add_child'
collect2: error: ld returned 1 exit status
here is a link to SQLSelectParser.l file which used ast_add_child().