使用Sublime Text 3构建C ++代码时,体系结构x86_64的未定义符号

时间:2015-03-24 06:36:17

标签: c++ sublimetext3 clang++

我刚开始在OS X中使用sublime text 3和Clang ++作为我的C ++开发工具集(来自windows中的visual studio)。出于某种原因,我得到了#34;架构x86_64"的未定义符号。每当我尝试编译时都会出错。代码在VS中正常工作(没有错误/警告)。我的智慧结束了。任何帮助将不胜感激。提前谢谢。

我的代码如下:

w4.cpp

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

    using namespace std;


    int main() {
      Date Date1("Elon Musk", 2015, 2, 5);
      Date Date2;

      cout << "Displaying the Dates..." << endl;
      Date1.display();
      Date2.display();

      cout << "Booking a new Date..." << endl;

      if (!Date1.hasConflict(Date2))
        Date2.book("Larry Page", 2015, 3, 14);
      else
        cout << "Sorry! This date is not available!" << endl;

      cout << "Cancelling a Date..." << endl;

      if (Date1.cancel())
        cout << "The Date is cancelled successfully!" << endl;
      else
        cout << "There is no Date to cancel!" << endl;

      cout << "Displaying the Dates..." << endl;
      Date1.display();
      Date2.display();

      return 0;
    }

Date.cpp

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include "Date.h"
#include <string.h>

void Date::book (const char name[], int year, int month, int day)
{
    strcpy (_name,name);

    if (year>=2015)
        _year=year;
    else
        std::cout<<"Year is invalid!"<<std::endl;

    if (month>=1 && month <=12)
        _month=month;
    else
        std::cout<<"Month is invalid!"<<std::endl;

    if (day>=1 && day<=31)
        _day=day;
    else
        std::cout<<"Day is invalid!"<<std::endl;
}

bool Date::isAvailable() const
{
    if (_name[0] == 0)
        return true;
    else
        return false;
}

bool Date::cancel()
{
    if (!isAvailable())
    {
        _month = 0;
        _day = 0;
        _year = 0;
        _name[0] = 0;
        return true;
    }
    else
        return false;
}

bool Date::hasConflict (const Date &date) const
{
    if (this->_day == date._day && this->_month == date._month && this->_year == date._year)
        return true;
    else
        return false;
}

void Date::display() const
{
    if (_year==0)
    {
        std::cout << "The date is not available to display!" << std::endl;
    }
    else
    {
        std::cout << _day << "/" << _month << "/" << _year << ": " << _name << std::endl;
    }

}

Date::Date () {
    _name[0] = 0;
    _day=0;
    _year=0;
    _month=0;

}

Date::Date(const char name[], int year, int month, int day)
{
    strcpy (_name,name);

    if (year>=2015)
        _year=year;
    else
        std::cout<<"Year is invalid!"<<std::endl;

    if (month>=1 && month <=12)
        _month=month;
    else
        std::cout<<"Month is invalid!"<<std::endl;

    if (day>=1 && day<=31)
        _day=day;
    else
        std::cout<<"Day is invalid!"<<std::endl;
}

Date::~Date(){


}

date.h

class Date {
private:
    char _name[41];
    int _year;
    int _month;
    int _day;

public:
    void book (const char name[], int year, int month, int day);
    bool isAvailable() const;
    bool cancel();
    bool hasConflict(const Date &date) const;
    void display() const;
    Date ();
    Date (const char Name[],int,int,int);
    ~Date();
};

错误

Undefined symbols for architecture x86_64:
  "Date::book(char const*, int, int, int)", referenced from:
      _main in w4-fa745d.o
  "Date::cancel()", referenced from:
      _main in w4-fa745d.o
  "Date::Date(char const*, int, int, int)", referenced from:
      _main in w4-fa745d.o
  "Date::Date()", referenced from:
      _main in w4-fa745d.o
  "Date::~Date()", referenced from:
      _main in w4-fa745d.o
  "Date::hasConflict(Date const&) const", referenced from:
      _main in w4-fa745d.o
  "Date::display() const", referenced from:
      _main in w4-fa745d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 0.2s with exit code 1]
[shell_cmd: g++ "/Users/Tom/Desktop/untitled folder 2/w4.cpp" -o "/Users/Tom/Desktop/untitled folder 2/w4"]
[dir: /Users/Tom/Desktop/untitled folder 2]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

0 个答案:

没有答案
相关问题