dimanche 28 juillet 2019

How to fix error Undefined symbols for architecture x86_64

I am trying to code a very simple class in C++11 but I am getting the compiler error 'Undefined symbols for architecture x86_64'. What does it mean? How do I deal with it?

I am using Visual Studio Code for MacOS and the compiler Clang-8 (updated 2 days ago).

Here are the 3 files I have written so far:

*------------------------------------------------------------------*/
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;
}
/*------------------------------------------------------------------*/

The full error message is:

Undefined symbols for architecture x86_64: "Point::Point(double, double)", referenced from: _main in cpp14test-15cf25.o "Point::Point()", referenced from: _main in cpp14test-15cf25.o ld: symbol(s) not found for architecture x86_64 clang-8: error: linker command failed with exit code 1 (use -v to see invocation) The terminal process terminated with exit code: 1

Aucun commentaire:

Enregistrer un commentaire