c ++ undefined对析构函数的引用

时间:2011-10-24 13:08:55

标签: c++ reference destructor undefined

对此抱歉,但我重新打开了这个。在对特征错误进行排序之后,这种裁剪再次向上重新启动。完全相同的代码完全相同的错误。 (好吧,这次编译器找到了本征头。)所以,同样的问题:

我搜索了析构函数c ++和未定义的引用无济于事。但是我很确定这对我来说是一个相当简单的问题。

错误:

/tmp/ccDsaJ9v.o: In function `main':
geomSetup.cpp:(.text+0x5ab): undefined reference to `SASAGeometry::~SASAGeometry()'
geomSetup.cpp:(.text+0x5cd): undefined reference to `SASAGeometry::~SASAGeometry()'
collect2: ld returned 1 exit status
make: *** [geomTest] Error 1

SASAGeometry.h:

class SASAGeometry
{
public:
//methods
  SASAGeometry() ;
  int makeFromFiles(char *, char *, char *) ;
  ~SASAGeometry() ;
//globals
  std::list<E......};

SASAGeometry.cpp

SASAGeometry::SASAGeometry(){}

int SASAGeometry::makeFromFiles(char * xyz_file, char * dat_file, char * atoms_file)
{
  sasa_transformMatrix basisMaker ;
  list<Vect...
...
}

SASAGeometry::~SASAGeometry(){}

geomTest.cpp

int main(int argv, char * argc[])
{
  list<Vector3d>::iterator listIterator ;
  char * xyz_file = argc[1] ;
  char * dat_file = argc[2] ;
  char * atoms_file = argc[3] ;
  SASAGeometry geomMaker ;
  int geomErr....

...
return 0 ;
}

makefile:

# compiler choice
CXX = g++

# executable path
BIN = .

# include paths (or lack thereof :p)
INCLUDE = -I .

# compilation flags
CXXFLAGS = -pipe # -O6

# linking flags
LFLAGS = -lm

# object declarations
GeomTest_OBJS = geomTest.o SASAGeometry.o

geomTest_source     = SASAGeometry.cpp SASAGeometry.h sasa_transformMatrix.cpp sasa_transformMatrix.h geomSetup.cpp

SASAGeometry.o  :   SASAGeometry.cpp SASAGeometry.h sasa_transformMatrix.cpp sasa_transformMatrix.h

geomTest.o  :   geomSetup.cpp SASAGeometry.o

# compile 
geomTest    : $(GeomTest_OBJS) makefile
            $(CXX) -o geomTest.o -o SASAGeometry.o $(LIBS) $(INCLUDE) $(CXXFLAGS) $(geomTest_source) $(LFLAGS)
            $(CXX) $(LIBS) $(INCLUDE) $(CXXFLAGS) -o $(BIN)/geomTest geomTest.o SASAGeometry.o $(LFLAGS)

clean       : \rm *.o *~ p1

我的INCLUDE和LIBS标志都可以,SASAGeometry类中的所有其他方法都非常愉快地定义。

提前致谢。

1 个答案:

答案 0 :(得分:6)

您没有在{0}中包含SASAGeometry.cppgeomTest.cpp。 makefile应该是这样的:

geomTest    : $(GeomTest_OBJS) makefile
            $(CC) -o geomTest.o -o SASAGeometry.o $(LIBS) $(INCLUDE) $(CFLAGS) $(geomTest_source) $(LFLAGS)
            $(CC) $(LIBS) $(INCLUDE) $(CFLAGS) -o $(BIN)/geomTest geomTest.o $(LFLAGS)