Cocos2dx Jni出现"无法解析的外部符号"错误,如何破

编码很酷 2014-07-30 10:34:49
错误信息:
错误	2	error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: static bool __cdecl 

cocos2d::JniHelper::getStaticMethodInfo(struct cocos2d::JniMethodInfo_ &,char const *,char const *,char const *)" (__imp_?

getStaticMethodInfo@JniHelper@cocos2d@@SA_NAAUJniMethodInfo_@2@PBD11@Z),该符号在函数 "public: void __thiscall HelloWorld::fun

(void)" (?fun@HelloWorld@@QAEXXZ) 中被引用 E:\安卓开发工作空间\cocos2d-x-2.2\projects\jni2\proj.win32\HelloWorldScene.obj

HelloCpp



源代码:
#include "HelloWorldScene.h"
#include "JniHelper.h"

USING_NS_CC;

CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();

// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();

// add layer as a child to scene
scene->addChild(layer);

// return the scene
return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}

CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.

// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));

pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));

// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);

/////////////////////////////
// 3. add your codes below...

// add a label shows "Hello World"
// create and initialize a label

CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);

// position the label on the center of the screen
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - pLabel->getContentSize().height));

// add the label as a child to this layer
this->addChild(pLabel, 1);

// add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::create("HelloWorld.png");

// position the sprite on the center of the screen
pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

// add the sprite as a child to this layer
this->addChild(pSprite, 0);

return true;
}


void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}

void HelloWorld::fun()
{
JniMethodInfo methodInfo;
bool isHave = JniHelper::getStaticMethodInfo(methodInfo,
"org/cocos2dx/hellocpp/HelloCpp", "showAd", "()V") ;

if(isHave)
{
methodInfo.env->CallStaticVoidMethod(methodInfo.classID,methodInfo.methodID);
}
}



#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

class HelloWorld : public cocos2d::CCLayer
{
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();

// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::CCScene* scene();

// a selector callback
void menuCloseCallback(CCObject* pSender);
void fun();

// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
};

#endif // __HELLOWORLD_SCENE_H__


这个问题如何破?
...全文
2425 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
笨木头 2014-07-30
  • 打赏
  • 举报
回复
你要加上平台判断,这代码要在Android端才能使用的,VS上编译不了,类似这样:

void JavaPlatform::callVoidMethod( const char* javaClassPath, const char* methodName ) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
JniMethodInfo minfo;
bool isHave = JniHelper::getStaticMethodInfo(minfo,javaClassPath,methodName,"()V");
#endif
}
zxx43 2014-07-30
  • 打赏
  • 举报
回复
开发android还是eclipse+cdt好
彩阳 2014-07-30
  • 打赏
  • 举报
回复
你需要Android SDK tools编译Android应用。
彩阳 2014-07-30
  • 打赏
  • 举报
回复
使用VS编译Android的应用?
笨木头 2014-07-30
  • 打赏
  • 举报
回复
引用 7 楼 Huang_Cai_Yuan 的回复:
[quote=引用 6 楼 musicvs 的回复:] 头文件你包含了吗
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

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


LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes\
                                  E:\安卓开发工作空间\cocos2d-x-2.2\cocos2dx\platform\android\jni

LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static

LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog


include $(BUILD_SHARED_LIBRARY)

$(call import-module,cocos2dx)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,CocosDenshion/android)
$(call import-module,extensions)
$(call import-module,external/Box2D)
$(call import-module,external/chipmunk)
我加了这句话"E:\安卓开发工作空间\cocos2d-x-2.2\cocos2dx\platform\android\jni"之后,就搞定了,神伤了一下午。 [/quote] 这样确实也可以~恭喜
编码很酷 2014-07-30
  • 打赏
  • 举报
回复
引用 6 楼 musicvs 的回复:
头文件你包含了吗
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

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


LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes\
                                  E:\安卓开发工作空间\cocos2d-x-2.2\cocos2dx\platform\android\jni

LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static

LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog


include $(BUILD_SHARED_LIBRARY)

$(call import-module,cocos2dx)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,CocosDenshion/android)
$(call import-module,extensions)
$(call import-module,external/Box2D)
$(call import-module,external/chipmunk)
我加了这句话"E:\安卓开发工作空间\cocos2d-x-2.2\cocos2dx\platform\android\jni"之后,就搞定了,神伤了一下午。
笨木头 2014-07-30
  • 打赏
  • 举报
回复
头文件你包含了吗
编码很酷 2014-07-30
  • 打赏
  • 举报
回复
引用 4 楼 musicvs 的回复:
你要加上平台判断,这代码要在Android端才能使用的,VS上编译不了,类似这样:

void JavaPlatform::callVoidMethod( const char* javaClassPath, const char* methodName ) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
	JniMethodInfo minfo;
	bool isHave = JniHelper::getStaticMethodInfo(minfo,javaClassPath,methodName,"()V");
#endif
}
嗯,后面我加了平台判断代码,但是移植到Android平台的时候,出现了如下问题:
"E:\\迅雷下载\\android-ndk-r9-windows-x86\\android-ndk-r9\\ndk-build.cmd" 
Android NDK: WARNING:E:\安卓开发工作空间\cocos2d-x-2.2\/cocos2dx/Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries    
"Compile++ thumb : cocos2dcpp_shared <= HelloWorldScene.cpp
jni/../../Classes/HelloWorldScene.cpp:3:23: fatal error: JniHelper.h: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o] Error 1
这个要怎么破?

8,322

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧