【发布时间】:2018-09-10 01:44:43
【问题描述】:
我正在尝试将我的 .cpp 实现文件与我的头文件链接 - 我从我的 mac 终端收到此错误消息 -
rowlandev:playground rowlandev$ g++ main.cpp -o main
Undefined symbols for architecture x86_64:
"Person::Person()", referenced from:
_main in main-32e73b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我的 cpp 文件中的代码:
#include <iostream>
#include "playground.h"
using namespace std;
Person::Person() {
cout << "this is running from the implementation file" << endl;
}
这是我的主要功能的代码:
#include <iostream>
#include "playground.h"
using namespace std;
int main() {
Person chase;
}
这是我的头文件中的代码:
#include <string>
using namespace std;
#ifndef playground_h
#define playground_h
class Person {
public:
Person();
private:
string name;
int age;
};
#endif /* playground_h */
我应该怎么做才能修复这个错误?随意添加我可以做的任何其他事情来改进我刚刚编写的代码。对任何事物开放。
【问题讨论】:
标签: c++ macos terminal header implementation