Kaptain
Kaptain

Reputation: 115

Many Errors with cocos2d-x-3.0 project creation

So I'm trying to setup a project using cocos2d-x-3.0. I can set everything up just fine, and then import and run my new project in Eclipse with no problems; however, once I open the main.cpp file for the first time, a bunch of errors pop up and I can no longer compile my project. The error it gives me is Unresolved inclusion: AppDelegate.h on the #include "AppDelegate.h"

#include "AppDelegate.h"
#include "cocos2d.h"
#include "CCEventType.h"
#include "platform/android/jni/JniHelper.h"
#include <jni.h>
#include <android/log.h>

#define  LOG_TAG    "main"
#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)

using namespace cocos2d;

void cocos_android_app_init (struct android_app* app) {
    LOGD("cocos_android_app_init");
    AppDelegate *pAppDelegate = new AppDelegate();
}

I then looked and noticed the Classes folder in my project was empty, despite there being classes in the Classes folder in the project. So I went and added a new Class folder with a link to the auto generated Classes folder in the project folder. This fixes the problem again, but if I open any of the files in my new Class folder, it highlights a TON of could not be resolved errors, and I can no longer compile. Here is part of my AppDelegate.h file:

#ifndef  _APP_DELEGATE_H_
#define  _APP_DELEGATE_H_

#include "cocos2d.h"

/**
@brief    The cocos2d Application.

The reason for implement as private inheritance is to hide some interface call by Director.
*/
class  AppDelegate : private cocos2d::Application
{

There is an error at the cocos2d::Application part saying Symbol 'Application' could not be resolved.

EDIT: After remaking the project, I discovered that the Classes folder is automatically marked as deprecated in Eclipse. I was able to make a new (non-linked) Class folder, and manually add the pre-made classes, and no longer was given any errors. I have no idea why this is, but it worked.

Scratch that, now I only get errors in one of the four files. In HelloWorldScene.cpp:

// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(  // Says "Invalid arguments" for the create call
                                       "CloseNormal.png",
                                       "CloseSelected.png",
                                       CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); // "Symbol'_1' could not be resolved" (What is Symbol_1)?

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

// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu, 1);

There are a few more Could not be resolved and Invalid arguments errors in there. What confuses me the most about this, is that everything compiles and runs just fine until I open the files and the errors load.

Upvotes: 1

Views: 2608

Answers (3)

Franz
Franz

Reputation: 675

I don't know why this happens but you can:

  1. right-click on you project in Eclipse "Package Explorer"
  2. click on "Run C/C++ Code Analysis"

This will remove the errors so you can build/run your project again.

Upvotes: 0

Jeff Tang
Jeff Tang

Reputation: 1804

Make sure of two things:

  1. Import the libcocos2dx under your own project directory, as documented here http://www.cocos2d-x.org/wiki/How_to_Build_an_Android_Project_with_Eclipse;

  2. In your Project - Properties - C/C++ General > Code Analysis, unselect Syntax and Semantic Errors - otherwise you'll see the error and won't be able to build from Eclipse.

enter image description here

Upvotes: 0

Singhak
Singhak

Reputation: 8896

At the movement you should use COCOCS 2d-x2.2 for creating project in cocos2d-x. it is easy and good. Try it.

One thing more that go to Projectproperty int eclips and codeAnalysis(in C/c++ Gneral) then click on use project setting the the UNMARK the CHECK box of SYantax and Semantics error. It will remove a lot of error

Upvotes: 2

Related Questions