undefined symbol yylex

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pavan734@gmail.com

    undefined symbol yylex

    Hello,
    Please excuse me as Iam not posting this to correct group. I
    have a parser code obtained from flex command. I have many other files.
    When I compile them Iam getting a message like: undefined symbol yylex.
    What might have went wrong?

  • tragomaskhalos

    #2
    Re: undefined symbol yylex

    pavan734@gmail. com wrote:
    Hello,
    Please excuse me as Iam not posting this to correct group. I
    have a parser code obtained from flex command. I have many other files.
    When I compile them Iam getting a message like: undefined symbol yylex.
    What might have went wrong?
    Two things to check spring to mind:
    - Ensure that you are incorporating the generated lex.yy.c file into
    your build
    - If you are invoking yylex from a C++ file, make sure you use extern
    "C" when declaring it.
    You'll probably also get a link error for a missing yywrap. If so write
    a simple C file with this in it:
    int yywrap()
    { return 1; }

    HTH.

    Comment

    • Robbie Hatley

      #3
      Re: undefined symbol yylex

      <pavan734@gmail .comwrote in message news:1152876087 .095516.180690@ m73g2000cwd.goo glegroups.com.. .
      Hello,
      Please excuse me as Iam not posting this to correct group. I
      have a parser code obtained from flex command. I have many other files.
      When I compile them Iam getting a message like: undefined symbol yylex.
      What might have went wrong?
      Compilers don't give error messages like that. That's a linker
      error. Your files all compiled fine, but the linker couldn't
      find something to link symbol yylex to. This can occur if you
      list the flex library on the gcc command line, even if you're
      not actually using flex in program. One thing that can cause
      that is, you tell gcc to compile and link a bunch of modules
      to an executable, but forget to include the module with main().

      For example, when I try to make an exe file out of a blank cpp
      file, like so:

      // Begin blank.cpp
      // (no content)
      // End blank.cpp

      gpp blank.cpp -lfl -o blank.exe

      Error: in function "_main": libmain.c:11: Undefined reference
      to symbol "_yylex". Collect2: ld returned 1 exit status.

      What happened is, gcc sees that you mentioned the flex library,
      so it assumes you want main() generated for you, and a reference
      in main to a (non-existant) yylex funtion. Since you never
      provided an actual flex file, there IS NO SUCH FUNCTION. So,
      you get that error.

      So, look to make sure you actually do have a main() function.
      More generally, look for files you may have forgotten to include
      in the build.

      --
      Cheers,
      Robbie Hatley
      East Tustin, CA, USA
      lone wolf intj at pac bell dot net
      (put "[usenet]" in subject to bypass spam filter)



      Comment

      • pavan734@gmail.com

        #4
        Re: undefined symbol yylex

        Thank you very much. I now used extern "C" and I got rid of the error.
        tragomaskhalos wrote:
        pavan734@gmail. com wrote:
        Hello,
        Please excuse me as Iam not posting this to correct group. I
        have a parser code obtained from flex command. I have many other files.
        When I compile them Iam getting a message like: undefined symbol yylex.
        What might have went wrong?
        >
        Two things to check spring to mind:
        - Ensure that you are incorporating the generated lex.yy.c file into
        your build
        - If you are invoking yylex from a C++ file, make sure you use extern
        "C" when declaring it.
        You'll probably also get a link error for a missing yywrap. If so write
        a simple C file with this in it:
        int yywrap()
        { return 1; }
        >
        HTH.

        Comment

        • pavan734@gmail.com

          #5
          Re: undefined symbol yylex

          Thank you for your kind information. I came to knew much about flex.
          Robbie Hatley wrote:
          <pavan734@gmail .comwrote in message news:1152876087 .095516.180690@ m73g2000cwd.goo glegroups.com.. .
          Hello,
          Please excuse me as Iam not posting this to correct group. I
          have a parser code obtained from flex command. I have many other files.
          When I compile them Iam getting a message like: undefined symbol yylex.
          What might have went wrong?
          >
          Compilers don't give error messages like that. That's a linker
          error. Your files all compiled fine, but the linker couldn't
          find something to link symbol yylex to. This can occur if you
          list the flex library on the gcc command line, even if you're
          not actually using flex in program. One thing that can cause
          that is, you tell gcc to compile and link a bunch of modules
          to an executable, but forget to include the module with main().
          >
          For example, when I try to make an exe file out of a blank cpp
          file, like so:
          >
          // Begin blank.cpp
          // (no content)
          // End blank.cpp
          >
          gpp blank.cpp -lfl -o blank.exe
          >
          Error: in function "_main": libmain.c:11: Undefined reference
          to symbol "_yylex". Collect2: ld returned 1 exit status.
          >
          What happened is, gcc sees that you mentioned the flex library,
          so it assumes you want main() generated for you, and a reference
          in main to a (non-existant) yylex funtion. Since you never
          provided an actual flex file, there IS NO SUCH FUNCTION. So,
          you get that error.
          >
          So, look to make sure you actually do have a main() function.
          More generally, look for files you may have forgotten to include
          in the build.
          >
          --
          Cheers,
          Robbie Hatley
          East Tustin, CA, USA
          lone wolf intj at pac bell dot net
          (put "[usenet]" in subject to bypass spam filter)
          http://home.pacbell.net/earnur/

          Comment

          • pavan734@gmail.com

            #6
            Re: undefined symbol yylex

            What is the significance of using extern "C". What makes using it to
            avoid link error

            tragomaskhalos wrote:
            pavan734@gmail. com wrote:
            Hello,
            Please excuse me as Iam not posting this to correct group. I
            have a parser code obtained from flex command. I have many other files.
            When I compile them Iam getting a message like: undefined symbol yylex.
            What might have went wrong?
            >
            Two things to check spring to mind:
            - Ensure that you are incorporating the generated lex.yy.c file into
            your build
            - If you are invoking yylex from a C++ file, make sure you use extern
            "C" when declaring it.
            You'll probably also get a link error for a missing yywrap. If so write
            a simple C file with this in it:
            int yywrap()
            { return 1; }
            >
            HTH.

            Comment

            • tragomaskhalos

              #7
              Re: undefined symbol yylex


              pavan734@gmail. com wrote:
              What is the significance of using extern "C". What makes using it to
              avoid link error
              Basically whenever you call C functions from C++ you must declare them
              as extern "C".
              Easiest explanation is to first Google for "C++ name mangling" and read
              up on that. Now, using extern "C" tells the compiler that the symbols
              in question (in this case yylex) come from C and have therefore not
              been mangled. I think there may be other ramifications to do with
              calling conventions but that's the gist of it.

              Comment

              • Howard

                #8
                Re: undefined symbol yylex


                "Robbie Hatley" <bogus.address@ no.spamwrote in message
                news:xFLtg.6527 1$Lm5.21722@new ssvr12.news.pro digy.com...
                <pavan734@gmail .comwrote in message
                news:1152876087 .095516.180690@ m73g2000cwd.goo glegroups.com.. .
                >Hello,
                > Please excuse me as Iam not posting this to correct group. I
                >have a parser code obtained from flex command. I have many other files.
                >When I compile them Iam getting a message like: undefined symbol yylex.
                >What might have went wrong?
                >
                Compilers don't give error messages like that. That's a linker
                error. Your files all compiled fine, but the linker couldn't
                find something to link symbol yylex to. This can occur if you
                list the flex library on the gcc command line, even if you're
                not actually using flex in program. One thing that can cause
                that is, you tell gcc to compile and link a bunch of modules
                to an executable, but forget to include the module with main().
                >
                For example, when I try to make an exe file out of a blank cpp
                file, like so:
                >
                // Begin blank.cpp
                // (no content)
                // End blank.cpp
                >
                gpp blank.cpp -lfl -o blank.exe
                >
                Error: in function "_main": libmain.c:11: Undefined reference
                to symbol "_yylex". Collect2: ld returned 1 exit status.
                >
                What happened is, gcc sees that you mentioned the flex library,
                so it assumes you want main() generated for you, and a reference
                in main to a (non-existant) yylex funtion. Since you never
                provided an actual flex file, there IS NO SUCH FUNCTION. So,
                you get that error.
                >
                So, look to make sure you actually do have a main() function.
                More generally, look for files you may have forgotten to include
                in the build.
                >
                You've shown an "undefined reference" error, which is indeed a linker error.
                But compilers do issue "undefined symbol" errors, which is what the OP said
                it was. They occur when the symbol (such as a variable name) hasn't been
                declared in the current scope. Different compilers may describe that
                differently ("undeclared ", "undefined" , "unknown", whatever), of course, but
                they do occur.

                You may be right that it was a linker error, but from the original post,
                there's no way to be sure of that (without some prior knowledge of that lex
                stuff). Which is just another reason why posters should include the text of
                the error message, and if it's a compile error, then the line(s) of code
                referred to as well.

                -Howard




                Comment

                • Default User

                  #9
                  Re: undefined symbol yylex

                  pavan734@gmail. com wrote:
                  Thank you for your kind information. I came to knew much about flex.
                  Robbie Hatley wrote:


                  Please don't top-post. Your replies belong following or interspersed
                  with properly trimmed quotes. See the newsgroup FAQ:
                  <http://www.parashift.c om/c++-faq-lite/how-to-post.html#faq-5.4>




                  Brian

                  Comment

                  Working...