c++对析构函数的未定义引用

发布于 2024-12-12 04:08:46 字数 2152 浏览 0 评论 0原文

对此感到抱歉,但我要重新打开它。对特征误差进行排序后,它又重新出现了。完全相同的代码完全相同的错误。 (好吧,编译器这次找到了特征标头。)所以,同样的问题:

我搜索了析构函数 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 类中的所有其他方法都定义得很愉快。

提前致谢。

Sorry about this, but I am re-opening this. After sorting the eigen errors, this cropped right back up again. Exactly the same code exactly the same error. (well, the compiler found the eigen headers this time.) So, same question:

I have searched for destructor c++ and undefined reference to no avail. However I am pretty sure this is a fairly simple slip on my part.

Error:

/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

My INCLUDE and LIBS flags are all ok, all other methods in the SASAGeometry class are quite happily defined.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2024-12-19 04:08:47

您没有将 SASAGeometry.cppgeomTest.cpp 一起包含在 makefile 中。 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)

You are not including SASAGeometry.cpp in makefile along with geomTest.cpp. makefile should be something like this:

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文