I wrote a few functions for using MoveBy actions in a header called CustomUtils.h. In one of the cpp files in my project, I decided to call one of its functions. But upon compiling the project, I got the LNK2019 error. The message:
error LNK2019: unresolved external symbol “void __cdecl moveBy(class cocos2d::Node *,float,float,float)” (?moveBy@@YAXPAVNode@cocos2d@@MMM@Z) referenced in function “private: void __thiscall ScoreKeeper::placeLabels(void)” (?placeLabels@ScoreKeeper@@AAEXXZ)
Apparently it thinks I didn’t do the implementation for the function I called. Except I very much did.
The header:
#pragma once
#include "cocos2d.h"
void moveBy(cocos2d::Node* node, float duration, cocos2d::Vec2& delta);
void moveBy(cocos2d::Node* node, float duration, float xDelta, float yDelta);
void xMoveBy(cocos2d::Node* node, float duration, float amount);
void yMoveBy(cocos2d::Node* node, float duration, float amount);
The implementation:
#include "cocos2d.h"
#include "CustomUtils.h"
using namespace cocos2d;
void moveBy(Node* node, float duration, Vec2& delta)
{
MoveBy* movement = MoveBy::create(duration, delta);
node->runAction(movement);
}
void moveBy(Node* node, float duration, float xDelta, float yDelta)
{
MoveBy* movement = MoveBy::create(duration, Vec2(xDelta, yDelta));
node->runAction(movement);
}
void xMoveBy(Node* node, float duration, float amount)
{
MoveBy* movement = MoveBy::create(duration, Vec2(amount, 0));
node->runAction(movement);
}
void yMoveBy(Node* node, float duration, float amount)
{
MoveBy* movement = MoveBy::create(duration, Vec2(0, amount));
node->runAction(movement);
}
All the implementations and includes are there. Both the cpp and h are included in the project (in the directories where the other headers and cpps I made are). Another thing I’d like to note is that the linker error only happens when I try to call any of the functions in Custom Utils; when I have those commented out, the project compiles fine. Even though the header is still included.
Is there something I’ve been missing? I’d really appreciate help with this.