linking error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sana24
    New Member
    • Sep 2006
    • 17

    linking error

    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(wincr t0.obj) : error LNK2001: unresolved external symbol _WinMain@16
    Debug/parseur_vhdl.ex e : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.
    parseur_vhdl.ex e - 3 error(s), 0 warning(s)


    Any help please!!
  • tyreld
    New Member
    • Sep 2006
    • 144

    #2
    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()" ).

    Comment

    • sana24
      New Member
      • Sep 2006
      • 17

      #3
      Originally posted by tyreld
      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.

      Comment

      • tyreld
        New Member
        • Sep 2006
        • 144

        #4
        Originally posted by sana24
        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.

        Comment

        • sana24
          New Member
          • Sep 2006
          • 17

          #5
          Originally posted by tyreld
          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

          Comment

          • tyreld
            New Member
            • Sep 2006
            • 144

            #6
            Originally posted by sana24
            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.

            Comment

            • sana24
              New Member
              • Sep 2006
              • 17

              #7
              Originally posted by tyreld
              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

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                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).

                Comment

                • sana24
                  New Member
                  • Sep 2006
                  • 17

                  #9
                  Originally posted by Banfa
                  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

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    Originally posted by sana24
                    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.

                    Comment

                    • sana24
                      New Member
                      • Sep 2006
                      • 17

                      #11
                      Originally posted by Banfa
                      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?

                      Comment

                      • Banfa
                        Recognized Expert Expert
                        • Feb 2006
                        • 9067

                        #12
                        Have you written a function called yylex?

                        Comment

                        • sana24
                          New Member
                          • Sep 2006
                          • 17

                          #13
                          Originally posted by Banfa
                          Have you written a function called yylex?
                          NO, but In the code there is
                          extern "C"
                          {int yylex(void);}

                          Comment

                          • tyreld
                            New Member
                            • Sep 2006
                            • 144

                            #14
                            Originally posted by sana24
                            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

                            Comment

                            • tyreld
                              New Member
                              • Sep 2006
                              • 144

                              #15
                              Originally posted by sana24
                              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.

                              Comment

                              Working...