CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    58

    linking errors: xxx already defined

    So here goes another linking error thread!

    I am forced to have the deceleration of a class template in the .h file.
    See here: http://forums.codeguru.com/showthrea...t=#post2081723

    This works perfectly fine, as long as i #inlcude the header file only in ONE .cpp file.
    The moment i #inlude it in several .cpp files, i get LNK2005 already-defined errors.

    a.obj : error LNK2005: "public: unsigned int * __thiscall theclass::themthod(void)" (?xxx@theclass@@QAEPAIXZ) already defined in b.obj

    I would have assumed inclusion guards can protect me from this, but wrong.


    After 4+ hours trying to figure this out, i am in desperate need for some help.


    nice weekend to everyone!

  2. #2
    Join Date
    Jun 2012
    Posts
    58

    Re: linking errors: xxx already defined

    wait.


    ok, i forgot to mention that the .h file in question held several thousand lines of code.
    Turns out two smaller non-template classes hid in between the templated code and accounted for the linking errors, the actual templates i cant outsource into a .cpp file compile fine. The problem was that said classes were defined in the .h file too and with all the template stuff around i missed that.

    Yeah, that`s how a whole firday goes to waste.

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: linking errors: xxx already defined

    Quote Originally Posted by tuli View Post
    ok, i forgot to mention that the .h file in question held several thousand lines of code.
    Turns out two smaller non-template classes hid in between the templated code and accounted for the linking errors, the actual templates i cant outsource into a .cpp file compile fine. The problem was that said classes were defined in the .h file too and with all the template stuff around i missed that.

    Yeah, that`s how a whole firday goes to waste.
    That's why the 'one class per header file' guideline is a good one to follow.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured