Linker problem with template traits/policy on MSVS 2005

This is a discussion on Linker problem with template traits/policy on MSVS 2005 within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, What compiles, links and runs perfectly on my home Linux station, compiled with GNU gxx-4. , does compile ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Hi everyone,

    What compiles, links and runs perfectly on my home Linux station, compiled with GNU gxx-4. , does compile but not link with VisualStudio 2005.

    The problem is that the linker apparently finds the copy constructor for my class Vector in the header Matrix.h too, but it just isn't there.
    The same actually holds for ALL operators !

    Voilà two of the error messages:

    [cc] Vector.obj : error LNK2005: "public: __thiscall LinAlg::Vector<class LinAlg::Complex>::Vector<class LinAlg::Complex>(class LinAlg::Vector<class LinAlg::Complex> const &)" (??0?$Vector@VCom
    plex@LinAlg@@@LinAlg@@QAE@ABV01@@Z) already defined in Matrix.obj
    [cc] Vector.obj : error LNK2005: "public: class LinAlg::Vector<class LinAlg::Complex> & __thiscall LinAlg::Vector<class LinAlg::Complex>:: operator=(class LinAlg::Vector<class LinAlg::Complex> c
    onst &)" (??4?$Vector@VComplex@LinAlg@@@LinAlg@@QAEAAV01@AB V01@@Z) already defined in Matrix.obj


    Thanks a lot for your help!!!

    Mark
    Attached Files Attached Files

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,145
    Despite looking like it, 'template<> Vector<Complex> :: Vector( Vector<Complex> const&);' *1 is not a template. It is just a function. Specifically: it is a function in a header that is not declared 'inline'. Solve this problem the way you would, your preference, for any other such "problematic" function.

    Edit: From what I can tell, MSVC has it right. I think 'LD' is just being a little to aggressive in ignoring multiple definitions for template functions.

    Soma

    *1:
    Code:
    template<> Vector<Complex> :: Vector( Vector<Complex> const&);

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Despite looking like it, *1 is not a template
    Yes, thanks for correcting my bad language.
    Specifically: it is a function in a header that is not declared 'inline'.
    So the problem is that it is in the header "Vector.h", which is included in "Matrix.h" ?
    Ok, and then we use 'inline' to not include it twice?

    Thanks!

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,145
    O_o

    Yes.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function template has already been defined
    By Elysia in forum C++ Programming
    Replies: 19
    Last Post: 04-14-2009, 10:17 AM
  2. Linker problem... no idea
    By cyreon in forum C Programming
    Replies: 2
    Last Post: 04-03-2009, 02:53 PM
  3. template class problem
    By l2u in forum C++ Programming
    Replies: 4
    Last Post: 02-13-2008, 01:10 PM
  4. 'Random' linker warnings VC++ 2005 Express
    By C+/- in forum C++ Programming
    Replies: 10
    Last Post: 01-12-2007, 01:26 PM
  5. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 05:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21