Flex/Bison: Multiple definition of 'said function'









up vote
0
down vote

favorite












Since my code is a bit too long, I thought it would be easier to post a github link if anyone is willing to help me and needs the code: https://github.com/Pigums/Cminus-Compiler



In cygwin, I run these commands:



bison -d step3.y
flex step3.fl
gcc step3.tab.c lex.yy.c -lfl -o step3


Then the following errors pop up:



/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x0): multiple definition of `CreateTemp'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x0): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x4a): multiple definition of `Insert'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x4a): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x140): multiple definition of `PrintSym'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x140): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x19f): multiple definition of `Display'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x19f): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x1e6): multiple definition of `Search'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x1e6): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x266): multiple definition of `Delete'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x266): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x2fd): multiple definition of `ASTCreateNode'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x2fd): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x3c0): multiple definition of `ASTattachleft'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x3c0): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x3f6): multiple definition of `PT'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x3f6): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0x427): multiple definition of `ASTprint'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0x427): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.text+0xa83): multiple definition of `compareFormals'
/tmp/ccfXBuoP.o:lex.yy.c:(.text+0xa83): first defined here
/tmp/ccdKHQL3.o:step3.tab.c:(.bss+0x0): multiple definition of `mem'
/tmp/ccfXBuoP.o:lex.yy.c:(.bss+0x14): first defined here
collect2: error: ld returned 1 exit status


Not sure what I'm doing wrong, tried looking up the error but I don't think the answers I got are the ones I'm looking for. What's the problem here?










share|improve this question

























    up vote
    0
    down vote

    favorite












    Since my code is a bit too long, I thought it would be easier to post a github link if anyone is willing to help me and needs the code: https://github.com/Pigums/Cminus-Compiler



    In cygwin, I run these commands:



    bison -d step3.y
    flex step3.fl
    gcc step3.tab.c lex.yy.c -lfl -o step3


    Then the following errors pop up:



    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x0): multiple definition of `CreateTemp'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x0): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x4a): multiple definition of `Insert'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x4a): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x140): multiple definition of `PrintSym'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x140): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x19f): multiple definition of `Display'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x19f): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x1e6): multiple definition of `Search'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x1e6): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x266): multiple definition of `Delete'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x266): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x2fd): multiple definition of `ASTCreateNode'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x2fd): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x3c0): multiple definition of `ASTattachleft'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x3c0): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x3f6): multiple definition of `PT'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x3f6): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x427): multiple definition of `ASTprint'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x427): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.text+0xa83): multiple definition of `compareFormals'
    /tmp/ccfXBuoP.o:lex.yy.c:(.text+0xa83): first defined here
    /tmp/ccdKHQL3.o:step3.tab.c:(.bss+0x0): multiple definition of `mem'
    /tmp/ccfXBuoP.o:lex.yy.c:(.bss+0x14): first defined here
    collect2: error: ld returned 1 exit status


    Not sure what I'm doing wrong, tried looking up the error but I don't think the answers I got are the ones I'm looking for. What's the problem here?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Since my code is a bit too long, I thought it would be easier to post a github link if anyone is willing to help me and needs the code: https://github.com/Pigums/Cminus-Compiler



      In cygwin, I run these commands:



      bison -d step3.y
      flex step3.fl
      gcc step3.tab.c lex.yy.c -lfl -o step3


      Then the following errors pop up:



      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x0): multiple definition of `CreateTemp'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x0): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x4a): multiple definition of `Insert'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x4a): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x140): multiple definition of `PrintSym'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x140): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x19f): multiple definition of `Display'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x19f): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x1e6): multiple definition of `Search'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x1e6): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x266): multiple definition of `Delete'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x266): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x2fd): multiple definition of `ASTCreateNode'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x2fd): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x3c0): multiple definition of `ASTattachleft'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x3c0): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x3f6): multiple definition of `PT'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x3f6): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x427): multiple definition of `ASTprint'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x427): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0xa83): multiple definition of `compareFormals'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0xa83): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.bss+0x0): multiple definition of `mem'
      /tmp/ccfXBuoP.o:lex.yy.c:(.bss+0x14): first defined here
      collect2: error: ld returned 1 exit status


      Not sure what I'm doing wrong, tried looking up the error but I don't think the answers I got are the ones I'm looking for. What's the problem here?










      share|improve this question













      Since my code is a bit too long, I thought it would be easier to post a github link if anyone is willing to help me and needs the code: https://github.com/Pigums/Cminus-Compiler



      In cygwin, I run these commands:



      bison -d step3.y
      flex step3.fl
      gcc step3.tab.c lex.yy.c -lfl -o step3


      Then the following errors pop up:



      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x0): multiple definition of `CreateTemp'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x0): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x4a): multiple definition of `Insert'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x4a): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x140): multiple definition of `PrintSym'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x140): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x19f): multiple definition of `Display'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x19f): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x1e6): multiple definition of `Search'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x1e6): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x266): multiple definition of `Delete'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x266): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x2fd): multiple definition of `ASTCreateNode'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x2fd): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x3c0): multiple definition of `ASTattachleft'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x3c0): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x3f6): multiple definition of `PT'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x3f6): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0x427): multiple definition of `ASTprint'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0x427): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.text+0xa83): multiple definition of `compareFormals'
      /tmp/ccfXBuoP.o:lex.yy.c:(.text+0xa83): first defined here
      /tmp/ccdKHQL3.o:step3.tab.c:(.bss+0x0): multiple definition of `mem'
      /tmp/ccfXBuoP.o:lex.yy.c:(.bss+0x14): first defined here
      collect2: error: ld returned 1 exit status


      Not sure what I'm doing wrong, tried looking up the error but I don't think the answers I got are the ones I'm looking for. What's the problem here?







      compiler-construction bison flex-lexer c-minus-minus






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 23:08









      PiguFilms

      63118




      63118






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted











          #include "symtable.c"
          #include "ast.c"



          That's your problem right there. By including those two C files in the requires section of step3.y, their contents end up in both lex.yy.c and step3.tab.c, so everything is defined twice.



          Instead you should include the header files, not the C files, and then compile and link ast.c and symbtable.c by passing them to gcc:



          gcc step3.tab.c lex.yy.c ast.c symtable.c -o step3


          (You could also use a Makefile to compile each file separately and then link them together, so you only need to recompile the files that have changed, but that's an entirely different matter)



          Note that this isn't specific to flex or bison. You shouldn't ever #include C-files unless you know exactly what this implies and you have a very good reason.






          share|improve this answer






















          • Ah, that makes a lot of sense! Thanks for the help!
            – PiguFilms
            Nov 12 at 6:47











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254160%2fflex-bison-multiple-definition-of-said-function%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted











          #include "symtable.c"
          #include "ast.c"



          That's your problem right there. By including those two C files in the requires section of step3.y, their contents end up in both lex.yy.c and step3.tab.c, so everything is defined twice.



          Instead you should include the header files, not the C files, and then compile and link ast.c and symbtable.c by passing them to gcc:



          gcc step3.tab.c lex.yy.c ast.c symtable.c -o step3


          (You could also use a Makefile to compile each file separately and then link them together, so you only need to recompile the files that have changed, but that's an entirely different matter)



          Note that this isn't specific to flex or bison. You shouldn't ever #include C-files unless you know exactly what this implies and you have a very good reason.






          share|improve this answer






















          • Ah, that makes a lot of sense! Thanks for the help!
            – PiguFilms
            Nov 12 at 6:47















          up vote
          2
          down vote



          accepted











          #include "symtable.c"
          #include "ast.c"



          That's your problem right there. By including those two C files in the requires section of step3.y, their contents end up in both lex.yy.c and step3.tab.c, so everything is defined twice.



          Instead you should include the header files, not the C files, and then compile and link ast.c and symbtable.c by passing them to gcc:



          gcc step3.tab.c lex.yy.c ast.c symtable.c -o step3


          (You could also use a Makefile to compile each file separately and then link them together, so you only need to recompile the files that have changed, but that's an entirely different matter)



          Note that this isn't specific to flex or bison. You shouldn't ever #include C-files unless you know exactly what this implies and you have a very good reason.






          share|improve this answer






















          • Ah, that makes a lot of sense! Thanks for the help!
            – PiguFilms
            Nov 12 at 6:47













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted







          #include "symtable.c"
          #include "ast.c"



          That's your problem right there. By including those two C files in the requires section of step3.y, their contents end up in both lex.yy.c and step3.tab.c, so everything is defined twice.



          Instead you should include the header files, not the C files, and then compile and link ast.c and symbtable.c by passing them to gcc:



          gcc step3.tab.c lex.yy.c ast.c symtable.c -o step3


          (You could also use a Makefile to compile each file separately and then link them together, so you only need to recompile the files that have changed, but that's an entirely different matter)



          Note that this isn't specific to flex or bison. You shouldn't ever #include C-files unless you know exactly what this implies and you have a very good reason.






          share|improve this answer















          #include "symtable.c"
          #include "ast.c"



          That's your problem right there. By including those two C files in the requires section of step3.y, their contents end up in both lex.yy.c and step3.tab.c, so everything is defined twice.



          Instead you should include the header files, not the C files, and then compile and link ast.c and symbtable.c by passing them to gcc:



          gcc step3.tab.c lex.yy.c ast.c symtable.c -o step3


          (You could also use a Makefile to compile each file separately and then link them together, so you only need to recompile the files that have changed, but that's an entirely different matter)



          Note that this isn't specific to flex or bison. You shouldn't ever #include C-files unless you know exactly what this implies and you have a very good reason.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 1:11

























          answered Nov 11 at 23:18









          sepp2k

          292k38593606




          292k38593606











          • Ah, that makes a lot of sense! Thanks for the help!
            – PiguFilms
            Nov 12 at 6:47

















          • Ah, that makes a lot of sense! Thanks for the help!
            – PiguFilms
            Nov 12 at 6:47
















          Ah, that makes a lot of sense! Thanks for the help!
          – PiguFilms
          Nov 12 at 6:47





          Ah, that makes a lot of sense! Thanks for the help!
          – PiguFilms
          Nov 12 at 6:47


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254160%2fflex-bison-multiple-definition-of-said-function%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          What does pagestruct do in Eviews?

          Dutch intervention in Lombok and Karangasem

          Channel Islands