linking error2005 visual studio 2008 c++

后端 未结 2 1681
走了就别回头了
走了就别回头了 2021-01-27 15:38

I had struct errorStruct & a queue errQueue definition in yacc.y , then moved it to separate .h file
but it gives me linking error that the definition is found in both y

相关标签:
2条回答
  • 2021-01-27 15:48

    I believe you should organize the code as:

    yacc.h   //-----> should have declaration of errQueue & errorStruct
    
    yacc.cc  //-----> should include yacc.h, 
    //It can create variables of type errQueue & errorStruct
    
    node.cc  //-----> should include yacc.h
    //It can create variables of type errQueue & errorStruct
    

    Note that the declarations should only be present in yacc.h and it should be included in all your cc files which need to create instances of the said types, If the structures are declared in any of your cc file in addition to the header(yacc.h) then you will end up getting the redefinition errors you mentiones.

    0 讨论(0)
  • 2021-01-27 16:03

    opss! I forgot to post the answer .. sorry ..

    got it with the help of @Peter K.'s reference :

    go to VS : project -> property page -> configuration properties -> linker ->command line

    and add /FORCE:MULTIPLE in additional options box

    0 讨论(0)
提交回复
热议问题