Undefined symbols for architecture x86_64: Layer::create()

Quick question for newbie. I spend hours but can not fix this error.

helloworld

 bool HelloWorld::init()
    {
        //////////////////////////////
        // 1. super init first
        if ( !Layer::init() )
        {
            return false;
        }
        
        abcLayer* gameLayer = abcLayer::createLayer();
        //this->addChild(gameLayer);
        
        return true;
    }

abcLayer.h

#include <iostream>
#include "cocos2d.h"
class abcLayer : public cocos2d::Layer
{
public:
    abcLayer();
    ~abcLayer();
    static abcLayer* createLayer();
    bool initLayer();
    //CREATE_FUNC(abcLayer);
};

abcLayer.cpp

#include "abcLayer.h"
USING_NS_CC;
abcLayer::abcLayer()
{
    
}

abcLayer::~abcLayer()
{
    
}

abcLayer* abcLayer::createLayer()
{
    abcLayer * pRet = new abcLayer();
    if (pRet && pRet->initLayer())
    {
        pRet->autorelease();
        return pRet;
    }
    else
    {
        delete pRet;
        pRet = NULL;
        return NULL;
    }
}

bool abcLayer::initLayer()
{
    if (!Layer::init())
    {
        return false;
    }

    return true;
}

linker error

ndefined symbols for architecture x86_64:
  "abcLayer::createLayer()", referenced from:
      HelloWorld::init() in HelloWorldScene.o
ld: symbol(s) not found for architecture x86_64

What is the problem -_-?

You declared it as a class function.
A static function is a class function, not a member function.

But you defined it as a member function.

Change it to abcLayer* createLayer()

The linker tries to get the symbols for your class function, but fails, as you never defined it.

Just use the CREATE_FUNC(abcLayer); makro. It will just do, what you have coded by hand.

thankyou for help :slight_smile: