体系结构x86_64的未定义符号:编译C ++ clang错误

时间:2019-06-20 15:32:22

标签: c++ aggregation composition clang++

我已经浏览了已经存在且标题相同的帖子,但是还没有找到解决此问题的解决方案。

我有5个文件

cmain.cpp

#include <iostream>
#include "People.h"
#include "Birthday.h"

using namespace std;

int main()
{
    Birthday birthObj(12, 28, 1986);

    People Player("Alex", birthObj);
    Player.printInfo(); 

}

Birthday.cpp

#include "Birthday.h"
#include <iostream>


using namespace std;

Birthday::Birthday(int m, int d, int y)
{
    month  = m;
    day = d; 
    year = y; 
}

void Birthday::printDate()
{
    cout << month << "/" << day << "/" << year << endl;
}

People.cpp

#include "People.h"
#include "Birthday.h"
#include <iostream>
#include "cmain.cpp"
using namespace std;


People::People(string x, Birthday bo)
: name(x), 
dateOfBirth(bo) 
{

}


void People::printInfo()
{
    cout << name << "was born on ";
    dateOfBirth.printDate();
}

People.h

#ifndef PEOPLE_H
#define PEOPLE_H

#include <string> 
#include "Birthday.h"
using namespace std;


class People
{
    public:
        People(string x, Birthday bo);
        void printInfo();
    private:
        string name;
        Birthday dateOfBirth;


};

#endif // PEOPLE_H

生日.h

#ifndef BIRTHDAY_H
#define BIRTHDAY_H 

using namespace std;


class Birthday 
{
    public:
        Birthday(int m, int d, int y);
        void printDate();

    private:
        int month;
        int day;
        int year;


};

#endif // BIRTHDAY_H

所以基本上,我试图使用合成(汇总方法)打印出玩家“ Alex”的名字和他的生日。

当我尝试使用命令

在终端(在Mac上为clang ++)上运行People.cpp时
g++ /Users/C++/People.cpp -o hw

我收到以下错误:

Undefined symbols for architecture x86_64:
  "Birthday::printDate()", referenced from:
      People::printInfo() in People-247742.o
  "Birthday::Birthday(int, int, int)", referenced from:
      _main in People-247742.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

使用Visual Studio Code 1.35.1

这是怎么了?

0 个答案:

没有答案