Vaughan Hilts
Vaughan Hilts

Reputation: 2879

ld: symbol(s) not found for architecture armv7 - Using a library?

I'm using Cocos2D-X, given the following code snippet:

CCSwipeGestureRecognizer * swipe = CCSwipeGestureRecognizer::create();
swipe->setTarget(this, callfuncO_selector(GameplayScene::didSwipe));
swipe->setDirection(kSwipeGestureRecognizerDirectionRight | kSwipeGestureRecognizerDirectionLeft);
swipe->setCancelsTouchesInView(true);
this->addChild(swipe);

I copied the provided CPP and H files over that I was given and they're added to the target. However, for some reason... this line:

swipe->setTarget(this, callfuncO_selector(GameplayScene::didSwipe));

is giving me issues. I can't even figure out what it's asking me -- let alone what to link for. The header is included and compiled.

    Undefined symbols for architecture armv7:
  "GameplayScene::didSwipe(cocos2d::CCObject*)", referenced from:
      GameplayScene::init() in GameplayScene.o
ld: symbol(s) not found for architecture armv7

Commenting out the setTarget line makes everything work fine.

Upvotes: 0

Views: 198

Answers (1)

FuzzyBunnySlippers
FuzzyBunnySlippers

Reputation: 3397

The simple answer here is that the function was not defined properly. It was defined as:

void didSwipe(CCObject* obj)
{
   exit(0);
}

It should have been:

void GameplayScene::didSwipe(CCObject* obj)
{
   exit(0);
}

That is to say, the implementation of the member function of the class and not just a function in the file.

BUT, and I want to stress this, while this may be the answer to the exact question, I don't think it is the answer to why this was a problem.

Some kind editor will probably come in and purge this for being off topic, but I'll put it in anyway...

Given:

  1. The author did look at this code for some time before seeing it (and I was in chat with him...as it appears at least one other was before me...before it was found).

  2. The author posted the API in the comments and it still was not obvious what the problem was.

  3. All the people who discussed and looked at the problem are of (reasonably) sound mind, body, and have at least a basic understanding that you actually have to tell the compiler a function is the implementation of a class function and not just a "function".

I think the real answer to this problem was:

  1. Don't try to write code after midnight...unless you are naturally nocturnal.

  2. Don't try to help people debug their code after midnight...unless you are naturally nocturnal.

  3. If the problem doesn't appear obvious in solution after you have looked at it for more than 1 hour, walk away and come back later.

  4. Don't feed developers after midnight or they may turn evil.

Yes, we have all broken these rules.

Upvotes: 1

Related Questions