Undefined symbols for arm64 when defining class initializer

Viewed 16

I have a simple class in C++ that I am defining in a separate header file since I want to then import it into a main file to work with other classes. I am defining this class in the following way.

TestClass.h

class TestClass {
    public:
        int first, second;
        TestClass(int, int);
};

TestClass.cpp

#include "TestClass.h"

TestClass::TestClass(int a, int b) {
    first = a;
    second = b;
}

Then, the main file looks as follows.

Test.cpp

#include "TestClass.h"

int main() {
    TestClass c(0, 1);
    return 0;
}

Then, I'm using the following command to compile:

g++ -o ./execute ./Test.cpp --std=c++11 

And I get:

Undefined symbols for architecture arm64:
  "TestClass::TestClass(int, int)", referenced from:
      _main in Test-3b63af.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

My g++ version is:

g++ -v
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.6.0
Thread model: posix

My guess from the error message is that this problem has something to do with my computer or the compiler settings, how can I fix it?

0 Answers
Related