Build failed for Win32 platform - "unresolved external symbol"

I’m trying to create a flappy bird clone, and I was testing my progress so far from the windows desktop executable and all was going well. I could see my background that I had put up. It was good.

Then I created the Bird class, and when referencing it in the init() of my main class (haven’t renamed it, it’s HelloWorldScene), I’m getting this error on MS VS 2010:

1>HelloWorldScene.obj : error LNK2019: unresolved external symbol "public: static class Bird * __cdecl Bird::createBirdWithFileName(char const *)" (?createBirdWithFileName@Bird@@SAPAV1@PBD@Z) referenced in function "public: virtual bool __thiscall HelloWorld::init(void)" (?init@HelloWorld@@UAE_NXZ) 1>C:\AndroidDev\cocos2d-x-2.2.1\projects\FlappyFux\proj.win32\Debug.win32\FlappyFux.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 5 up-to-date, 0 skipped ==========

My Bird.h:
`

#ifndef __BIRD_H__
#define __BIRD_H__

#include "cocos2d.h"


class Bird: public cocos2d::CCSprite {

	public:
		static Bird* createBirdWithFileName( const char *filename);
		void updateBird(float dt);
		void resetBird();
		int getState();
		void setState(int state);
		void setStartSpeed();

	private:
		static const int StartSpeedY;
		int _state;
		int _speedY;




};

#endif /* __BIRD_H__ */

`

My Bird.cpp:
`
#include “Bird.h”

USING_NS_CC;


Bird* createBirdWithFileName(const char *fileName)
{

	 Bird *pobSprite = new Bird();
	    if (pobSprite && pobSprite->initWithFile(fileName))
	    {
//	        pobSprite->scheduleUpdate();
	        pobSprite->autorelease();
	        return pobSprite;
	    }
	    CC_SAFE_DELETE(pobSprite);
		return NULL;

}

void Bird::updateBird(float dt)
{

}

void Bird::resetBird()
{

}

int Bird::getState()
{
return 0;
}

void Bird::setState(int state)
{

}

void Bird::setStartSpeed()
{

}

`

Here’s my HelloWorldScene.cpp:

`
#include “HelloWorldScene.h”
#include “Bird.h”

USING_NS_CC;

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    CCLabelTTF* pLabel = CCLabelTTF::create("Flappy Fux", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::create("FLBG-HD.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    
    bird_ = Bird::createBirdWithFileName("bird-HD.png");
    bird_->setPosition(ccp(visibleSize.width/4 + origin.x, visibleSize.height/3 + origin.y));
    this->addChild(bird_,2);

    this->setTouchEnabled(true);
    return true;
}

void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* event)
{

}

void HelloWorld::ccTouchesMoved(CCSet* touches, CCEvent* event)
{

}

void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
    CCSetIterator i;
    CCTouch *touch; 
    CCPoint tap;

    for(i = touches->begin(); i!=touches->end(); i++ )
    {
        touch = (CCTouch *)(*i);
        if(touch)
        {
            tap = touch->getLocation();
            CCLOG("Touched at %.2f, %.2f",tap.x,tap.y);

        }
    }
}

void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
	CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
    CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
#endif
}

`

What am I doing wrong? I know that if I were adding another class when working for Android, I’d have to add the added class files in the Android.mk make file. Is there something similar to do when working with MS VS 2010 for win32?

Been struggling with this stupid stupid error for the last 4+ hours. I had to finally give up and start writing code for other parts of the problem.

Then I realized my mistake:
In Bird.cpp, I wrote this:

Bird* createBirdWithFileName(const char *fileName)

Instead of this:

Bird* Bird::createBirdWithFileName(const char *fileName)

Forgot that I was not writing that func in the class somehow…

Also, can the moderators please delete this post? I don’t think it’s valuable to take up server space.

In your Bird.cpp,
Bird* createBirdWithFileName(const char *fileName)
should be
Bird* Bird::createBirdWithFileName(const char *fileName)

It was useful, John. Rarely using static stuff, I did the same mistake. :sweat_smile: