我有我的main.cc,是
#include <iostream>
#include "Sally.h"
using namespace std;
int main(){
Sally sallyObject;
sallyObject.printCrap();
}
和头文件Sally.h,即
#ifndef SALLY_H
#define SALLY_H
class Sally{
public:
Sally();
void printCrap();
protected:
private:
};
#endif //BURRITO_H
和Sally.cc,即
#include "Sally.h"
#include <iostream>
using namespace std;
Sally::Sally()
{
}
void Sally::printCrap(){
cout << "did someone say steak?" << endl;
}
,这三个文件位于同一目录中。
键入g++ main.cc
时,无法构建代码。它说
Undefined symbols for architecture x86_64:
"Sally::printCrap()",referenced from:
_main in main-16cd07.o
"Sally::Sally()",referenced from:
_main in main-16cd07.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
有人知道为什么会这样吗?