3

I have a class where I am trying to define several static/const objects of a custom type. The header file looks roughly like this:

#ifndef SRC_TEMPCONT_HXX
#define SRC_TEMPCONT_HXX

class TC
{
public:

// ... misc stuff ...

  class Register
  {
  public:

    //... misc stuff ...

    enum Access { Read=0x1, Write=0x2, ReadWrite=0x3 };

    //constructor
    Register(uint16_t address, Access access, size_t size);

    //series of static variables
    static Register 
    Setpoint1, SetpointSafetyCheck, Temperature,
      SecurityByte, RampByte, DisplayByte, DisplayState, Model,
      CommAddress, CommBaud, CommDataType, CommDebug,
      ProgramRun,
       Input, Unit,
      SoftwareVersion,
      MaxProgram, Program;

  };

};


#endif //TEMPCONT_HXX

In the cxx file I instantiate the variables like this:

TC::Register TC::Register::Setpoint1           (0x007F, ReadWrite, 2);
TC::Register TC::Register::SetpointSafetyCheck (0x0125, ReadWrite, 1);
TC::Register TC::Register::Temperature         (0x001C, Read,      2);
//etc...

My makefile compiles with the following command which I believe is correct:

g++ -g -Wall -DOS_LINUX -g -lm -lz -lutil -lnsl -lpthread -lrt -Isrc -I/home/deap/ovendaq/midas/include -I/home/deap/ovendaq/midas/drivers/divers src/obj/cont_test.o src/obj/TempCont.o src/obj/TimeoutSerial.o -L/home/deap/ovendaq/midas/linux-m64/lib -lmidas -lboost_system -lboost_program_options -o bin/cont_test.exe

But I am getting this bizarre error for each variable:

src/obj/TempCont.o:/usr/include/boost/noncopyable.hpp:24: multiple definition of `TC::Register::Setpoint1'
src/obj/cont_test.o:/home/deap/dev/OvenProject/src/cont_test.cxx:14: first defined here
src/obj/TempCont.o:/usr/include/boost/system/error_code.hpp:350: multiple definition of `TC::Register::SetpointSafetyCheck'
src/obj/cont_test.o:/home/deap/dev/OvenProject/src/cont_test.cxx:16: first defined here
src/obj/TempCont.o:/usr/include/boost/exception/exception.hpp:344: multiple definition of `TC::Register::Temperature'
src/obj/cont_test.o:/home/deap/dev/OvenProject/src/cont_test.cxx:18: first defined here
//etc... 

Why does it seem to think I am declaring the variables within the boost libraries? I have tested this exact same structure in a simplified program and it worked properly, but I can't figure out why it's not working here. What am I doing wrong?

TIA

4
  • Perhaps one of the .o files wasn't recompiled in a while (perhaps due to a problem in the Makefile)? Or something funny you do in TempCont.o -- you didn't say much about that file.
    – jogojapan
    Aug 24, 2012 at 0:59
  • 4
    You need to reproduce the problem in a small self-contained program. Aug 24, 2012 at 1:00
  • Alright I did make clean and then recompiled everything, and now it works fine. Guess it was just some weird issue with linking old object files. No idea why it was giving me files from the boost library as error locations though. Thanks for replies.
    – smead
    Aug 24, 2012 at 1:04
  • Just an unrelated tip, when linking you should place all libraries at the end of the command line, not at the beginning as you do. Aug 24, 2012 at 5:47

0

Browse other questions tagged or ask your own question.