c ++与静态成员变量的奇怪错误

时间:2012-08-24 00:47:09

标签: c++ class static linker

我有一个类,我试图定义自定义类型的几个静态/ const对象。头文件看起来大致如下:

#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

在cxx文件中,我实例化了这样的变量:

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

我的makefile使用以下命令编译,我认为这是正确的:

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

但是我为每个变量得到了这个奇怪的错误:

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

为什么它似乎认为我在升级库中声明了变量?我已经在一个简化的程序中测试了这个完全相同的结构并且它工​​作正常,但我无法弄清楚为什么它在这里不起作用。我做错了什么?

TIA

0 个答案:

没有答案