By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,233 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

linking error

P: 17
Hello all,
I use microsoft visual studio 6.0 and i have this error when I try to built my application :

vhdl.obj : error LNK2001: unresolved external symbol _yylex
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/parseur_vhdl.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
parseur_vhdl.exe - 3 error(s), 0 warning(s)


Any help please!!
Oct 4 '06 #1
Share this Question
Share on Google+
24 Replies


100+
P: 144
Its hard to say for sure since you haven't supplied any of your code for us to look at. However, my first guess is that you aren't linking all the necessary object files (ie. the linker can't find the following functions "yylex()" and "WinMain()").
Oct 4 '06 #2

P: 17
Its hard to say for sure since you haven't supplied any of your code for us to look at. However, my first guess is that you aren't linking all the necessary object files (ie. the linker can't find the following functions "yylex()" and "WinMain()").
vhdl.o is from vhdl.c, this file is generated by bison. My application is a vhdl parser.
Oct 4 '06 #3

100+
P: 144
vhdl.o is from vhdl.c, this file is generated by bison. My application is a vhdl parser.
Okay, the problem is that bison only generates the necessary code for parsing some set of tokens. The parsing code expects a function yylex for obtaining tokens. Generally, your lexer code would be generated by flex or lex. Finally neither one of these code generators produces a main method. You need to supply the rest of this code to produce a working application.
Oct 4 '06 #4

P: 17
Okay, the problem is that bison only generates the necessary code for parsing some set of tokens. The parsing code expects a function yylex for obtaining tokens. Generally, your lexer code would be generated by flex or lex. Finally neither one of these code generators produces a main method. You need to supply the rest of this code to produce a working application.
In addition, i have a main.c which is an application using this parser
Oct 4 '06 #5

100+
P: 144
In addition, i have a main.c which is an application using this parser
It would seem that main.o isn't being supplied to the linker at link time then.
Oct 4 '06 #6

P: 17
It would seem that main.o isn't being supplied to the linker at link time then.
I check it main.o is supplied to the linker
Oct 4 '06 #7

Banfa
Expert Mod 5K+
P: 8,916
You have compiler/linker options set that tell the compiler/linker that it is linking a Windows program and to look for WinMain as the entry point instead of main.

However you have supplied a main (because it is a console application?).

Check your linker options (and then your compiler options).
Oct 4 '06 #8

P: 17
You have compiler/linker options set that tell the compiler/linker that it is linking a Windows program and to look for WinMain as the entry point instead of main.

However you have supplied a main (because it is a console application?).

Check your linker options (and then your compiler options).
I changed the type of my projetc win32 application to win32 consol application.
I have now one error just:
vhdl.obj : error LNK2001: unresolved external symbol _yylex
Oct 4 '06 #9

Banfa
Expert Mod 5K+
P: 8,916
I changed the type of my projetc win32 application to win32 consol application.
I have now one error just:
vhdl.obj : error LNK2001: unresolved external symbol _yylex
which tyreId has already addressed in this post.

basically it can't locate it because you haven't written it.
Oct 4 '06 #10

P: 17
which tyreId has already addressed in this post.

basically it can't locate it because you haven't written it.
i don't understand you?what is the problem?
Oct 4 '06 #11

Banfa
Expert Mod 5K+
P: 8,916
Have you written a function called yylex?
Oct 4 '06 #12

P: 17
Have you written a function called yylex?
NO, but In the code there is
extern "C"
{int yylex(void);}
Oct 4 '06 #13

100+
P: 144
i don't understand you?what is the problem?
A parser is made up of two parts, a lexical analyzer and a syntactic/semantic analyzer. Although, problematically the term "parser" is often used to describe both the syntatctic/semantic analyzer as well as the combination of both the lexical and syntactic/semantic analyzers.

1.) Lexical analysis breaks the source language text into small pieces called tokens. Each token is a single atomic unit of the language, for instance a keyword, identifier or symbol name. The token syntax is typically a regular language, so a finite state automaton constructed from a regular expression can be used to recognize it. This phase is also called lexing or scanning, and the software doing lexical analysis is called a lexical analyzer or scanner.

2.) Syntax analysis involves parsing the token sequence to identify the syntactic structure of the program.

3.) Semantic analysis is the phase that checks the meaning of the program to ensure it obeys the rules of the language. One example is type checking. A parser emits most diagnostics during semantic analysis, and frequently combines it with syntax analysis.

Bison is a parser generator. However, it only generates code that deals with the phases described in item 2 and item 3. What this means is that the code generated by Bison requires a seperate implementation of the lexical phase described in item 1.

Bison provides a function called yyparse that is the entry point into the parser. However, yyparse expects a function called yylex to be defined to generate tokens from the source language. You either have to write this function yourself, or use a lexical analyzer generator tool like flex to generate it for you.

The following page provides some good resources on building parsers/compilers using Lex/Yacc or the modern GNU equivalents Flex/Bison.

The Lex and Yacc Page
Oct 4 '06 #14

100+
P: 144
NO, but In the code there is
extern "C"
{int yylex(void);}
That is simply telling the compiler that a function "yylex" is declared in a seperate source file, and that it should not treat the non-existance of that function in source file being compiled as an error. This is necessary because as I described before Bison generates a function yyparse that is dependent on the existance of a function yylex to function properly.
Oct 4 '06 #15

P: 17
which tyreId has already addressed in this post.

basically it can't locate it because you haven't written it.
But this code work well on linux. The problem on linux we use the option -lfl in the link. But on windows i don't know a flex library.
I want to link files generated by flex and bison on visual studio C++.
but i have this error:
vhdl.obj : error LNK2001: unresolved external symbol _yylex
I think that there is a flex library missed. But i don't find a win32 version of flex library.
Can you please help me
Oct 6 '06 #16

100+
P: 144
I'm at a lost as how that code would work on Linux. Linking against the Flex library doesn't provide a magical yylex implementation. If it did that would mean some how the Flex library just happens to know what tokens need to be recognized in your VHDL language. You are responsible for writing a lexical specification that contains the definitions of the tokens the lexer needs to recogonize. From this specification Flex generates C code. This C code contains an implementation of yylex. The Flex library only provides a main method that allows you to test a lexer you've defined against some input on stdin. I can only assume at some point in porting this application to Windows you neglected to include the lexer specification file used by Flex to generate the lexer code.
Oct 6 '06 #17

P: 17
I'm at a lost as how that code would work on Linux. Linking against the Flex library doesn't provide a magical yylex implementation. If it did that would mean some how the Flex library just happens to know what tokens need to be recognized in your VHDL language. You are responsible for writing a lexical specification that contains the definitions of the tokens the lexer needs to recogonize. From this specification Flex generates C code. This C code contains an implementation of yylex. The Flex library only provides a main method that allows you to test a lexer you've defined against some input on stdin. I can only assume at some point in porting this application to Windows you neglected to include the lexer specification file used by Flex to generate the lexer code.
I have three files:
lexx.yy.c generated by flex from vhdl.l
vhdl.c generated by bison from vhdl.y
main.c application to use the parser
on linux i havn't error, in fact flex and bison are installed on linux.
but i d'ont find a version of flex and bison on win32, just flex.exe and bison.exe to generate c files.
How can i include the lexer specification file used by Flex to generate the lexer code,
please it's very urgent to run this application on windows
Oct 6 '06 #18

100+
P: 144
I've never used flex or bison on windows. It sounds like bison is generating a vhdl.c. Is flex on windows generating lex.yy.c?
Oct 6 '06 #19

P: 17
I've never used flex or bison on windows. It sounds like bison is generating a vhdl.c. Is flex on windows generating lex.yy.c?
yes it generates lex.yy.c
Oct 6 '06 #20

100+
P: 144
Okay, is lex.yy.c being compiled into lex.yy.o? If so, is lex.yy.o being included in as a necessary object file at link time?
Oct 6 '06 #21

P: 17
Okay, is lex.yy.c being compiled into lex.yy.o? If so, is lex.yy.o being included in as a necessary object file at link time?
yes lex.yy.c is compiled into lex.yy.o, but i don't include it in the link.
Oct 9 '06 #22

P: 17
Okay, is lex.yy.c being compiled into lex.yy.o? If so, is lex.yy.o being included in as a necessary object file at link time?
yes lex.yy.c is compiled into lex.yy.o, but i don't include it in the link.
Is it the problem?
Oct 9 '06 #23

P: 17
yes lex.yy.c is compiled into lex.yy.o, but i don't include it in the link.
Is it the problem?
i include the lex.yy.o in the link but I still have the same error:
vhdl.obj: unresolved extern symbol_yylex
Oct 9 '06 #24

P: 1
Hi,

this link may help you..

http://clemens.bytehammer.com/papers/FlexTutorial/flex-vs_tutorial.html
Oct 22 '06 #25

Post your reply

Sign in to post your reply or Sign up for a free account.