Simple example of EditBox error.

Simple example of EditBox error.
0.0 0



I have a problem trying to add an EditBox to the example game (created by, using cocos2d-x 2.2.2, Fedora 20 and EClipse Kepler,

I added in the 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));

Added to my HelloWorldScene.h

#include "cocos-ext.h"

And got an error

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

So I added to my makefile

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

and now I get another error, see below my makefile and the error



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 \

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

SHAREDLIBS += -lcocos2d

	@mkdir -p $(@D)

	@mkdir -p $(@D)

$(OBJ_DIR)/%.o: ../%.cpp $(CORE_MAKEFILE_LIST)
	@mkdir -p $(@D)

Console Log

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)

Does anyone know why is this happening?



I noticed some error like that too in my game. I ended up including a relative path to the CCEditBox file and typedefing it over to my own internal type so I don’t have to worry about it more than once. Using a relative path is easiest way to at least get it to compile that I know


@Jgod Thanks for the reply.
Where did you include your relative path (on eclipse or makefile?) and how did you make the typedefing…
Sorry I am new to all this


I’m on cocos2d-x v2.2.1 so my project is in embedded below the cocos2d-x source, in projects/mygame (Is yours the same structure?). If you only need to include it a couple times, you can do an include like #include "../../../../extensions/GUI/CCEditBox/CCEditBox.h"


@Jgod Yes I have the same structure. I have tried to include CCEditbox.h as you suggest but i still get the same errors as above
**undefined reference to `cocos2d::extension::…
I 'm not sure what is wrong. A path, the linker, cocos setup ?


@Jgod Are you on Fedora 20 and eclipse too?


I’m on OSX and it works for me both on Xcode and Eclipse (my exact relative path will be different than yours, since my classes are in subfolders). If you’re certain that’s the right path, maybe try a new project? Cocos2d-x is usually pretty good out of the box, and copying over things to a new project has saved me in the past. I can’t see anything else immediately wrong based on what you posted


@Jgod Thanks for your help. Tried that too but nothing… I think there is something wrong with the linker… Anyway, I ll revert if I solve the problem somehow.



I had seen this problem while compiling my game with cocos2d-x v3.0 for Android and fixed it by using:

#include "extensions/cocos-ext.h"

Not sure if that will work for v2.2.2, though (I’ve only used the 3.0 pre-releases). Like you, I didn’t have the “extensions” in the path at first and it worked for iOS but not Android, so I checked the code samples and that’s how I saw the proper way to do it.