如何修复错误x86_64体系结构的未定义符号

时间:2019-07-29 01:08:43

标签: macos c++11 visual-studio-code

我正在尝试在C ++ 11中编写一个非常简单的类,但出现编译器错误“体系结构x86_64的未定义符号”。这是什么意思?我该如何处理?

我正在使用Visual Studio Code for MacOS和编译器Clang-8(两天前更新)。

这是我到目前为止编写的3个文件:

*------------------------------------------------------------------*/
class Point
{
    // Type declaration statements for data members
    private:
    double xCoord, yCoord; // Class atributes

    public:
    // Declaration statements for class methods
    // Constructors for Point class
    Point(); // Default constructor
    Point(double x, double y); // Parameterized constructor
};
/*------------------------------------------------------------------*/

/*------------------------------------------------------------------*/
#include "Point.h" // Required
#include<iostream> // Required for cout

using namespace std;

// Default constructor
Point::Point()
{
    cout << "Constructing point object, default: \n";
    cout << "Initializing to zero" << endl;
    xCoord = 0.0;
    yCoord = 0.0;
}

// Parameterized constructor
Point::Point(double x, double y)
{
    // Input paraneters x and y
    cout << "Constructing point object, parameterized: \n";
    cout << "Input parameters: " << x << "," << y << endl;
    xCoord = x;
    yCoord = y;
}
/*------------------------------------------------------------------*/

/*------------------------------------------------------------------*/
#include<iostream> 
#include "Point.h"

using namespace std;

int main()
{
    // Declare and initialize objects
    cout << "In main, declare p1... " << endl;
    Point p1;
    cout << "\nIn main, declare p2... " << endl;
    Point p2{1.5, -4.7};
    return 0;
}
/*------------------------------------------------------------------*/

完整的错误消息是:

体系结构x86_64的未定义符号:   从以下位置引用的“ Point :: Point(double,double)”       _main在cpp14test-15cf25.o中   从以下位置引用的“ Point :: Point()”       _main在cpp14test-15cf25.o中 ld:找不到架构x86_64的符号 clang-8:错误:链接器命令失败,退出代码为1(使用-v查看调用) 终端进程终止于退出代码:1

0 个答案:

没有答案