johnbakers
johnbakers

Reputation: 24771

simple linker error, can't find solution

I'm a bit new to C++ but this should be really simple for someone with a bit more experience to find, as I've been staring at it for a while now.

I have a class that has another class instance as an ivar:

private:
Test test1;

Then I have test.hpp:

class Test{
int x;
void tester();
public:
Test(); //constructor
};

And test.cpp:

 Test::Test():x(5){
    tester();
}

void Test::tester(){
std::cout<<x;
}

When I attempt to run, I get this:

Test::Test() referenced from <my original class with the test1 ivar> not found in architecture

Now I have plenty of other C++ code working fine, so the "architecture," whatever that means, is clearly supporting the language fine (I'm using Xcode).

What could be causing this linker error?

Upvotes: 0

Views: 91

Answers (1)

Macmade
Macmade

Reputation: 54039

Make sure the C++ file containing your test class is compiled and is actually linked with the final executable.

In Xcode, it means assigning the C++ file to the target.

Upvotes: 3

Related Questions