linking error2005 visual studio 2008 c++


I had struct errorStruct & a queue errQueue definition in yacc.y , then moved it to separate .h file<br /> but it gives me linking error that the definition is found in both yacc.obj and node.obj !!<br /> tried creating new solution but still gives the same error

Error 9 error LNK2005: "class std::queue<struct errorStruct,class std::deque<struct errorStruct,class std::allocator<struct errorStruct> > > errQueue" (?errQueue@@3V?$queue@UerrorStruct@@V? $deque@UerrorStruct@@V?$allocator@UerrorStruct@@@std@@@std@@@std@@A) already defined in Node.obj yacc.obj <h3>update</h3>

first :<br /> Node.h // for node class<br /> yacc.y // rules + errorStruct + queue errQueue + class ErrList : includes "Node.h" & < queue>


Node.h // for node class + errorStruct + queue errQueue + class ErrList : includes < queue><br /> yacc.y // rules : includes "Node.h"


in Node.h

struct errorStruct{ int errLineNum; int errColNum ; char * errMessage; }; class ErrList{ public: void pushError(int line,int col,char * message); void popError(); void printErrors(); int getSize(); private : queue <errorStruct> errQueue; }; externErrList * se = new ErrList ();

the rest of Node.h has nothing to do with this class<br /> in yacc.y just using<br />se->pushError(...);<br /> and as no declaration of class ErrList or errQueue


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.


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


  • Storing user details in application variable
  • How do I make TextBlock render overflowing text when using WrapWithOverflow? (without clipping)
  • c - Error: “incomplete type is not allowed” , IAR compiler
  • parsing xml with jsoup (while avoiding tags)
  • How to run a jar file from another jar
  • How to enable Drag a Marker (Android Map Api v2) after a single Touch?
  • How do I fix “The program issued a command but the command length is incorrect.” error when calling
  • Error Processing Request: Mage registry key “_singleton/inchoo_notes/feed_updates” already exists
  • FlexJSON Orders Alphabetically by Default
  • What is the quartz default thread count
  • How to use ResourceDictionary in Windows Phone class library project
  • Autohotkey script running program with command line arguments
  • VORA Tables in Zeppelin and Spark shell
  • How to set `secure` and `httpOnly` for Plones `__ac` cookie?
  • CSS Grid, position absolute an element in a css grid item: IMPOSSIBLE
  • goJS dropdown remove items
  • c++ using primitive types as a base class
  • Caret disappears when the background of a textbox is gray in wpf
  • Raphael.js function getBBox give back NAN/NAN/NAN in IE8
  • Javascript Array, Object, Date not defined
  • Losing my session variables
  • Ruby 1.8.6 Array#uniq not removing duplicate hashes
  • Get a trait object reference from a vector
  • Xmonad multiple submap key combos
  • php script is parsing content from RTE (tt_news) but internal links are not appearing as speaking ur
  • How can I mock ui-router's resolve values when testing a state's configuration?
  • KnockoutObservableArray with typed elements in TypeScript
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • Subclassing QGraphicsItem prevents me from being able to use itemAt() on a QGraphicsScene/View
  • CakePHP ACL tutorial initDB function warnings
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • one Local Olampyad Questions on Informatic in 2011
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • KeystoneJS: Relationships in Admin UI not updating
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Sorting a 2D array using the second column C++
  • How can i traverse a binary tree from right to left in java?
  • java string with new operator and a literal
  • Net Present Value in Excel for Grouped Recurring CF