2016-09-19 95 views
0
Undefined symbols for architecture x86_64: 
    "Matrix::~Matrix()", referenced from: 
     _main in p1.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

当我尝试在xcode中编译时出现此错误。问题出在头文件中的这个析构函数声明中。如果我评论析构函数,它会成功建立。Xcode未定义符号〜析构函数

class Matrix { 
public: 
    ~Matrix();  
}; 
+3

你在哪里定义析构函数? – NathanOliver

+0

我有三个文件:main,Matrix.hpp和Matrix.cpp。析构函数在Matrix.hpp中声明,并将在Matrix.cpp中定义。 – Char

+0

在Matrix.cpp中定义了什么?它真的被编译/链接? –

回答

0

您还没有定义析构函数。当你注释掉它时,析构函数将是一个隐式声明的析构函数,因此链接程序会找到它。您声明“...将被定义”。这是否意味着你还没有定义它?

从cppreference.com(http://en.cppreference.com/w/cpp/language/destructor

如果提供了一类式(结构, 类或联合)无用户声明的析构函数,编译器将总是声明析构函数作为 内嵌其同类公共成员。