   Linker error( multiple class definitions? )
  I have the following error messages-------------- Build: Release in ngn1 ---------------Compiling: src/main.cppLinking console executable: bin/Release/ngn1obj/Release/src/main.o: In function `ngn::Bracket_minimum::Bracket_minimum(double, double)':main.cpp:(.text+0x0): multiple definition of `ngn::Bracket_minimum::Bracket_minimum(double, double)'obj/Release/src/Compute_minimum_box.o:Compute_minimum_box.cpp:(.text+0x0): first defined hereobj/Release/src/main.o: In function `ngn::Bracket_minimum::Bracket_minimum(double, double)':main.cpp:(.text+0x20): multiple definition of `ngn::Bracket_minimum::Bracket_minimum(double, double)'obj/Release/src/Compute_minimum_box.o:Compute_minimum_box.cpp:(.text+0x20): first defined hereobj/Release/src/main.o: In function `ngn::Brent::Brent(unsigned int, double, double)':main.cpp:(.text+0x40): multiple definition of `ngn::Brent::Brent(unsigned int, double, double)'obj/Release/src/Compute_minimum_box.o:Compute_minimum_box.cpp:(.text+0x40): first defined hereobj/Release/src/main.o: In function `ngn::Brent::Brent(unsigned int, double, double)':main.cpp:(.text+0x60): multiple definition of `ngn::Brent::Brent(unsigned int, double, double)'obj/Release/src/Compute_minimum_box.o:Compute_minimum_box.cpp:(.text+0x60): first defined hereobj/Release/src/main.o: In function `ngn::Powell::Powell(unsigned int, double, double)':main.cpp:(.text+0x80): multiple definition of `ngn::Powell::Powell(unsigned int, double, double)'obj/Release/src/Compute_minimum_box.o:Compute_minimum_box.cpp:(.text+0x80): first defined hereobj/Release/src/main.o: In function `ngn::Powell::Powell(unsigned int, double, double)':main.cpp:(.text+0xa0): multiple definition of `ngn::Powell::Powell(unsigned int, double, double)'obj/Release/src/Compute_minimum_box.o:Compute_minimum_box.cpp:(.text+0xa0): first defined hereobj/Release/src/main.o:(.rodata+0x0): multiple definition of `ngn::Traits<ngn::Vector3>::n_elems'obj/Release/src/Compute_minimum_box.o:(.rodata+0x0): first defined herecollect2: ld a retourné 1 code d'état d'exécutionProcess terminated with status 1 (0 minutes, 7 seconds)0 errors, 0 warnings I simply know that when I remove Compute_box_minimum.* and Powell.h, the compilation succeeds.How should I read the compiler output?Could someone give me an idea of how to solve that kind of problems generally?P.S:I am using codeblocks 8.02 with gcc 4.1.2    
  Are you using include guards?   ;Quote:Original post by MikeTacularAre you using include guards?Yes, and codeblocks generates them when using the class wizard.That's why I am quite puzzled by the compile errors...P.S:[Edited by - johnstanp on June 15, 2009 3:16:07 PM];  Grep for all instances of #include Compute_box_minimum in your code.Search your file system for all files named Compute_box_minimum.*.Post all code that is the implementation or interface ofBrent::Brent(unsigned int, double, double)including what file it is in.As a theory, are you including the implementation of a function or method in a header file?;  Are you using the inline keyword correctly?   ;Quote:Original post by NotAYakkGrep for all instances of #include Compute_box_minimum in your code.Search your file system for all files named Compute_box_minimum.*.Post all code that is the implementation or interface ofBrent::Brent(unsigned int, double, double)including what file it is in.As a theory, are you including the implementation of a function or method in a header file?Only for classes that have a function template "template< > ... operator()(...)". Bracket_minimum, Brent, Powell and a few other classes don't have implementation files. I will create them and see what happens.   ;Quote:Original post by BregmaAre you using the inline keyword correctly?I never use it.   ;  Where isBracket_minimum::Bracket_minimum(double, double)declared?  implemented?  (name the file)Copy out the contents of where it in implemented.Is Bracket_minimum a template class?Include the prototype of the class Bracket_minimum.  Include the declaration of the Bracket_minimum constructor.Do you know what the inline keyword does?  (hint: it is only tangentially related to making code inline)   ;  Well, everything is now OK. I simply separated the implementation from the header files.I have a question: it is not allowed to define an explicit specialization inside the file where the template class is defined?I had previously this:#ifndef TRAITS_H#define TRAITS_H#include "Vector3.h"namespace ngn{    template< class T >    struct Traits    {   static size_t const n_elems;    };    template< >    struct Traits< Vector3 >    {   static size_t const n_elems;    };    size_t const Traits< Vector3 >::n_elems = 3;} And after defining the specialization inside the Vector.cpp file, the project compiles.#include "../include/Vector3.h"#include "../include/Traits.h"namespace ngn{    template< >    struct Traits< Vector3 >    {   static size_t const n_elems;    };    size_t const Traits< Vector3 >::n_elems = 3;    Vector3::Vector3()    {    }    Vector3::Vector3( Real x, Real y, Real z )   :x( x ), y( y ), z( z )    {    }...} [Edited by - johnstanp on June 15, 2009 5:17:13 PM];Quote:Original post by NotAYakkIs Bracket_minimum a template class?No but I know that template classes must be entirely defined in its header...Since I had a whole protect where everything was a class template.Quote:Do you know what the inline keyword does?  (hint: it is only tangentially related to making code inline)Yes I know( well, I thought I kew perfectly ). I used it massively for my project before reimplementing it without a single template class. Well, I never had a problem with it since there were no implementation file.Is it correct to infer that a class that doesn't have an implementation file( thus entirely defined in its .hpp file ) must only be included in another .hpp file?[Edited by - johnstanp on June 15, 2009 5:47:33 PM]