c++ strange error with static member variables [closed]

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

preguntado el 24 de agosto de 12 a las 01:08

Quizás uno de los .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. -

You need to reproduce the problem in a small self-contained program. -

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. -

Just an unrelated tip, when linking you should place todos libraries at the end of the command line, not at the beginning as you do. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.