Using Clion with Mac OS and I keep getting linker command failed with exit code 1 error, how do I fix it?

My code will not run no matter what I change, and I’m not sure what this error actually means. I just started this class so I have to use clion, which I am fairly new to. This is cloned from github to clion.

Tried to compile my code and I keep getting this error:

Undefined symbols for architecture arm64:
  "getPosition(Particle const*)", referenced from:
      (anonymous namespace)::ParticleFixture_TestGetPosition_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestGetPosition_Test::TestBody() in particle_unittest.cc.o
  "moveCoord3D(Coord3D*, Coord3D const*, double)", referenced from:
      (anonymous namespace)::ParticleFixture_TestMoveCoord3D_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestMoveCoord3D_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestMoveCoord3D_Test::TestBody() in particle_unittest.cc.o
  "deleteParticle(Particle const*)", referenced from:
      (anonymous namespace)::ParticleFixture_TestCreateDeleteParticle_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestCreateDeleteParticle_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestGetPosition_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestGetPosition_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestMoveParticle_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestSetVelocity_Test::TestBody() in particle_unittest.cc.o
  "length(Coord3D const*)", referenced from:
      (anonymous namespace)::ParticleFixture_TestLength_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestLength_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestLength_Test::TestBody() in particle_unittest.cc.o
      (anonymous namespace)::ParticleFixture_TestLength_Test::TestBody() in particle_unittest.cc.o
  "Particle::_num_allocations", referenced from:
      Particle::getNumAllocations() in particle_unittest.cc.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

This is my code.

main.cc

int main() {
    Coord3D pointP = {10, 20, 30};
    Coord3D pointQ = {-20, 21, -22};

    std::cout << "Address of P: " << &pointP << std::endl;
    std::cout << "Address of Q: " << &pointQ << std::endl << std::endl;

    Coord3D *ans = fartherFromOrigin(&pointP, &pointQ);

    std::cout << "ans = " << ans << std::endl; // So which point is farther?

    //task c

    Coord3D pos = {0, 0, 100.0};
    Coord3D vel = {1, -5, 0.2};

    std::cout << "Initial position: " << pos.x << " " << pos.y << " " << pos.z << std::endl;

    moveCoord3D(&pos, &vel, 2.0); // object pos gets changed

    std::cout << "New position: " << pos.x << " " << pos.y << " " << pos.z << std::endl;
    // prints: 2 -10 100.4
    // task D

    double x, y, z;
    std::cout << "Enter position: ";
    std::cin >> x >> y >> z;
    Coord3D *ppos = createCoord3D(x, y, z);

    std::cout << "Enter velocity: ";
    std::cin >> x >> y >> z;
    Coord3D *pvel = createCoord3D(x, y, z);

    moveCoord3D(ppos, pvel, 10.0);

    std::cout << "Coordinates after 10 seconds: "
         << (*ppos).x << " " << (*ppos).y << " " << (*ppos).z << std::endl;

    deleteCoord3D(ppos); // release memory
    deleteCoord3D(pvel);

    //task E
    Particle *p = createParticle(1.0, 1.5, 2.0, 0.1, 0.2, 0.3);
    double time = 0.0;
    double dt = 0.1;
    while(time < 3.0) {
        setVelocity(p, 10.0 * time, 0.3, 0.1);
        moveParticle(p, dt);
        time += dt;
        std::cout << "Time: " << time << " t";
        std::cout << "Position: "
             << getPosition(p).x << ", "
             << getPosition(p).y << ", "
             << getPosition(p).z << std::endl;
    }
    deleteParticle(p);
    return EXIT_SUCCESS;
}

Particle.cc

#include <iostream>
#include <cmath>

class Coord3D {
public:
    double x;
    double y;
    double z;
};



double length(Coord3D *p) {
    // Dereference the pointer to access x, y, z coordinates
    double x = p->x;
    double y = p->y;
    double z = p->z;
    // Compute the distance using the Euclidean distance formula
    double distance = sqrt(x * x + y * y + z * z);
    return distance;
}

Coord3D *fartherFromOrigin(Coord3D *p1, Coord3D *p2) {
    if (length(p1) > length(p2)) {
        return p1;
    } else {
        return p2;
    }
}

Coord3D* createCoord3D(double x, double y, double z) {
    Coord3D *p = new Coord3D;
    p->x = x;
    p->y = y;
    p->z = z;
    return p;
}

void deleteCoord3D(Coord3D *p) {
    delete p;
}

void moveCoord3D(Coord3D *ppos, Coord3D *pvel, double dt) {
    ppos->x += pvel->x * dt;
    ppos->y += pvel->y * dt;
    ppos->z += pvel->z * dt;
}

struct Particle {
    Coord3D pos;
    Coord3D vel;
};

Particle* createParticle(double x, double y, double z, double vx, double vy, double vz) {
    Particle *p = new Particle;
    p->pos.x = x;
    p->pos.y = y;
    p->pos.z = z;
    p->vel.x = vx;
    p->vel.y = vy;
    p->vel.z = vz;
    return p;
}

void setVelocity(Particle *p, double vx, double vy, double vz) {
    p->vel.x = vx;
    p->vel.y = vy;
    p->vel.z = vz;
}

Coord3D getPosition(Particle *p);

Coord3D getPosition(Particle *p) {
    return p->pos;
}

void moveParticle(Particle *p, double dt) {
    p->pos.x += p->vel.x * dt;
    p->pos.y += p->vel.y * dt;
    p->pos.z += p->vel.z * dt;
}

void deleteParticle(Particle *p) {
    delete p;
}

Particle.h

#ifndef PARTICLE_H
#define PARTICLE_H

#include <cstdlib>

struct Coord3D {
    double x;
    double y;
    double z;
};

// get the distance from the given coordinate to the origin
double length(const Coord3D* p);

// return the coordinate that's farthest from the origin
Coord3D* fartherFromOrigin(Coord3D* p1, Coord3D* p2);

// advance the position of the coordinate traveling at a given speed for a
// given time
void moveCoord3D(Coord3D* ppos, const Coord3D* pvel, double dt);

struct Particle {
public:
    double x;
    double y;
    double z;
    double vx;
    double vy;
    double vz;

    static size_t getNumAllocations() { return _num_allocations; }

    void* operator new(const size_t t) {
        (void)t;
        _num_allocations++;
        return ::new Particle();
    }

    void operator delete(void *const p) {
        _num_allocations--;
        free(p);
    }

private:
    static size_t _num_allocations;
};

// dynamically allocate memory for a particle and initialize it
Particle* createParticle(double x, double y, double z,
                         double vx, double vy, double vz);

// set its velocity to (vx, vy, vz)
void setVelocity(Particle* p, double vx, double vy, double vz);

// get its current position
Coord3D getPosition(const Particle* p);

// update particle's position after elapsed time dt
void moveParticle(Particle* p, double dt);

// delete all memory allocated for the particle passed by pointer
void deleteParticle(const Particle* p);

#endif // PARTICLE_H

New contributor

Lucy Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật