Cocos2d-x undefined link

We are looking for some help, new to cocos2dx and having error.iam using the Eclipse IDE

inside HelloWorld.cpp iam:

_backgroundNode = CCParallaxNodeExtras::node(); 

and it gives me an undefined reference error that looks like this

undefined reference to 'CCParallaxNodeExtras :: node ()'

My CCParallaxNodeExtras.h header file code is as follows: it inherits CCParallaxNode

 using namespace cocos2d; #include "cocos2d.h" class CCParallaxNodeExtras : public cocos2d::CCParallaxNode { public : // Need to provide a constructor CCParallaxNodeExtras(); // just to avoid ugly later cast and also for safety static CCParallaxNodeExtras* node(); // Facility method (it's expected to have it soon in COCOS2DX) void incrementOffset(CCPoint offset, CCNode* node); }; #endif 

here is CCParallaxNodeExtras.cpp

 #include "CCParallaxNodeExtras.h" using namespace cocos2d; // Hack to access CCPointObject (which is not a public class) class CCPointObject : cocos2d::CCObject { CC_SYNTHESIZE(cocos2d::CCPoint, m_tRatio, Ratio) CC_SYNTHESIZE(cocos2d::CCPoint, m_tOffset, Offset) CC_SYNTHESIZE(cocos2d::CCNode *, m_pChild, Child) // weak ref }; // Need to provide a constructor CCParallaxNodeExtras::CCParallaxNodeExtras() { cocos2d::CCParallaxNode(); // call parent constructor } CCParallaxNodeExtras* CCParallaxNodeExtras::node() { return new CCParallaxNodeExtras::CCParallaxNode(); } void CCParallaxNodeExtras::incrementOffset(cocos2d::CCPoint offset,CCNode *node){ for( unsigned int i = 0; i < m_pParallaxArray->num; i++) { CCPointObject *point = (CCPointObject *)m_pParallaxArray->arr[i]; CCNode *curNode = point->getChild(); if( curNode->isEqual(node) ) { point->setOffset( ccpAdd(point->getOffset(), offset) ); break; } } } 

Please answer, I know that there is a lot of code above, but I want to know if I am doing something wrong. Any help or suggestion would be appreciated. Thanks!

Sincerely, Muhammad Tahir Ashraf

+4
source share
2 answers

You should add a link to the new cpp file in Android.mk of the corresponding jni directory.

In my case, the file "Android.mk" is located on the route: {PROJ_DIRECTORY} \ proj.android \ jni

Edit this file and add a link to the CCParallaxNodeExtras cpp as follows:

In the LOCAL_SRC_FILES section that you have:

 LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp 

Now enable CCParallasNodeExtras.cpp. It should look like this:

 LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp \ ../../Classes/CCParallaxNodeExtras.cpp 

This should solve the problem. Create and run.

+15
source

It looks like you have a problem in defining the CCParallaxNodeExtras :: node () method. It should look like this:

 CCParallaxNodeExtras* CCParallaxNodeExtras::node() { return new CCParallaxNodeExtras(); } 

I think this should solve the problem. Let me know if this is not the case.

+1
source

Source: https://habr.com/ru/post/1487712/


All Articles