cocos2d-x EditBox的简单示例,错误未定义引用

时间:2014-02-21 13:41:38

标签: c++ makefile cocos2d-x fedora

尝试使用cocos2d-x 2.2.2,Fedora 20和Eclipse Kepler将示例游戏(由create_project.py创建)添加到EditBox时,我遇到了一个问题,

我在HelloWorldScene.cpp中添加了

using namespace cocos2d::extension;
using namespace cocos2d::gui;

CCEditBox *m_pEditName = CCEditBox::create(ccp(100,100),CCScale9Sprite::create("input_field.png"));
m_pEditName->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height*3/4));
m_pEditName->setFontColor(ccRED);
m_pEditName->setPlaceHolder("Name:");
m_pEditName->setMaxLength(8);
m_pEditName->setReturnType(kKeyboardReturnTypeDone);
addChild(m_pEditName);

添加到我的HelloWorldScene.h

#include "cocos-ext.h"

并收到错误

fatal error: cocos-ext.h: No such file or directory

我意识到编译器正试图在/ usr / include或/ usr / local / include中找到.h文件,所以我添加到了我的makefile

INCLUDES += -I$(COCOS_ROOT)/extensions
INCLUDES += -I$(COCOS_ROOT)/external/chipmunk/include/chipmunk

现在我收到另一个错误,请参阅下面的makefile和错误

MAKEFILE

EXECUTABLE = thief

COCOS_ROOT = ../../..

INCLUDES = -I.. -I../Classes
INCLUDES += -I$(COCOS_ROOT)/extensions
INCLUDES += -I$(COCOS_ROOT)/external/chipmunk/include/chipmunk
#INCLUDES += -I$(COCOS_ROOT)/cocos2dx/kazmath/include
#INCLUDES += -I$(COCOS_ROOT)/cocos2dx/include
#INCLUDES += -I$(COCOS_ROOT)/cocos2dx
#INCLUDES += -I$(COCOS_ROOT)/external/
#INCLUDES += -I$(COCOS_ROOT)/CocosDenshion/include
#INCLUDES += -I$(COCOS_ROOT)/extensions/netwrok
#INCLUDES += -I$(COCOS_ROOT)/external/libwebsockets/win32/include


SOURCES = main.cpp \
        ../Classes/AppDelegate.cpp \
        ../Classes/HelloWorldScene.cpp


include $(COCOS_ROOT)/cocos2dx/proj.linux/cocos2dx.mk

SHAREDLIBS += -lcocos2d
COCOS_LIBS = $(LIB_DIR)/libcocos2d.so

$(TARGET): $(OBJECTS) $(STATICLIBS) $(COCOS_LIBS) $(CORE_MAKEFILE_LIST)
    @mkdir -p $(@D)
    $(LOG_LINK)$(CXX) $(CXXFLAGS) $(OBJECTS) -o $@ $(SHAREDLIBS) $(STATICLIBS)

$(OBJ_DIR)/%.o: %.cpp $(CORE_MAKEFILE_LIST)
    @mkdir -p $(@D)
    $(LOG_CXX)$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@

$(OBJ_DIR)/%.o: ../%.cpp $(CORE_MAKEFILE_LIST)
    @mkdir -p $(@D)
    $(LOG_CXX)$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@

控制台日志

02:56:14 **** Auto Build of configuration Default for project thief ****
make all 
 CXX obj/release/main.o
 CXX obj/release/Classes/AppDelegate.o
 CXX obj/release/Classes/HelloWorldScene.o
 LINK bin/release/thief
obj/release/Classes/AppDelegate.o: In function `_GLOBAL__sub_I_AppDelegate.cpp':
AppDelegate.cpp:(.text.startup+0x72): undefined reference to     cocos2d::gui::Margin::Margin()'
obj/release/Classes/HelloWorldScene.o: In function `HelloWorld::init()':
HelloWorldScene.cpp:(.text+0x50f): undefined reference to     cocos2d::extension::CCScale9Sprite::create(char const*)'
HelloWorldScene.cpp:(.text+0x53f): undefined reference to     cocos2d::extension::CCEditBox::create(cocos2d::CCSize const&,     cocos2d::extension::CCScale9Sprite*, cocos2d::extension::CCScale9Sprite*,     cocos2d::extension::CCScale9Sprite*)'
HelloWorldScene.cpp:(.text+0x59c): undefined reference to     cocos2d::extension::CCEditBox::setFontColor(cocos2d::_ccColor3B const&)'
HelloWorldScene.cpp:(.text+0x5ab): undefined reference to     cocos2d::extension::CCEditBox::setPlaceHolder(char const*)'
HelloWorldScene.cpp:(.text+0x5b8): undefined reference to     cocos2d::extension::CCEditBox::setMaxLength(int)'
HelloWorldScene.cpp:(.text+0x5c5): undefined reference to     cocos2d::extension::CCEditBox::setReturnType(cocos2d::extension::KeyboardReturnType)'
obj/release/Classes/HelloWorldScene.o: In function `_GLOBAL__sub_I_HelloWorldScene.cpp':
HelloWorldScene.cpp:(.text.startup+0x72): undefined reference to     cocos2d::gui::Margin::Margin()'
collect2: error: ld returned 1 exit status
make: *** [bin/release/thief] Error 1

02:56:15 Build Finished (took 777ms)

有谁知道为什么会这样?

为了设置我的cocos2d-x我使用了这个说明 Building Cocos2d-x on RHEL / Fedora / CentOS Linux

由于

1 个答案:

答案 0 :(得分:1)

您需要添加&#34;扩展/ CocoStudio / GUI / Layouts / UILayoutDefine.cpp&#34;或删除&#34; cocos-ext.h&#34;从你的代码。