[Solved] Error LNK2019 happens despite nothing seeming to be wrong

[Solved] Error LNK2019 happens despite nothing seeming to be wrong
0.0 0

#1

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.


#2

I don’t see anything wrong with your code.

Check the file names. Check that it is located in the right place.


#3

I did. The files are in the folders that my other headers and cpps are in, and I don’t get any errors from those. Here’s a snippet of the hierarchy: https://i.imgur.com/2uSNHDY.png


#4

Linker Tools Error LNK2019

https://msdn.microsoft.com/en-us/library/799kze2z.aspx

By the way, you can upload images directly to the forum using the Upload button.

upload


#5

I looked through that list, and none of those issues apply. :confused: Again, I put the cpp and header in the right directories like I did for the other files, and those didn’t generate any errors.


#6

I remember it, I just know that sometimes developers forget to mention some modifications. I do not mean specifically you.

There is a little chance that this is a VS issue. Try to create a new project.


#7

can you run cocos new ... and successfully compile the result?


#8

Understood. And after making a new project and copy-pasting everything over, it worked! The stuff I wanted to use my moveBy functions moved as intended :slight_smile: Thanks for the help, guys.


#9

I’m glad that you solved it.