gpt4 book ai didi

c++ - cocos2d-x EditBox的简单例子,报错undefined reference to

转载 作者:行者123 更新时间:2023-11-28 07:04:45 27 4
gpt4 key购买 nike

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

我在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 和错误

生成文件

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

谢谢

最佳答案

您需要在代码中添加“extensions/CocoStudio/GUI/Layouts/UILayoutDefine.cpp”或删除“cocos-ext.h”。

关于c++ - cocos2d-x EditBox的简单例子,报错undefined reference to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21936080/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com