Gotchas: Using Cocos2d-x libExtensions and libNetwork

This tutorial is compatible with Cocos2d-x 3.0.

Some features of Cocos2d-x such as EditBox and HttpClient are not in the main libCocos2d project and in order to access them, other projects should be imported to the solution first. In this post, I am going to explain how to import and link external projects to the main game project. This post can also help people with general problems regarding referencing C++ projects in Visual Studio.

First, we need to import the libExtensions and libNetwork projects to our solution. To do this, right click on your Solution in the Solution Explorer window, hover over the Add item and press Existing Project….

The libExtensions.vcxproj project file is located at cocos2dextensionsproj.win32 and the libNetwork.vcxproj is located at cocos2dcocosnetworkproj.win32. After importing them, you need to link them to your main project.

To add references to other projects, you need to go to the property pages of your main project. Right click on your project and press Properties.

From Common Propertiesclick on the Add New Reference…button and check the boxes next to libExtensions and libNetwork.

One last thing that you need to do before using libExtensions, is to add $(EngineRoot) to your projects include directories. In Property Pages, open Configuration Properties>C/C++>General, and add $(EngineRoot); to Additional Include Directories.

There is one additional dependency that you probably might need to add to the libNetwork project. It requires the libcurl_imp.lib file to build, and we can set this by opening the Property Pages of libNetwork, locating Additional Dependencies at Configuration Properties>Librarian>General and adding $(EngineRoot)externalcurlprebuiltwin32libcurl_imp.lib; to the beginning of it.


Now you are all set to use libExtensions and libNetwork. For example, to create an EditBox, after adding the #include “extensions/GUI/CCEditBox/CCEditBox.h” line to the top of your file, you can use this code:

nameBox = cocos2d::extension::EditBox::create(Size(width, height), Scale9Sprite::createWithSpriteFrameName(“editBox”));

nameBox->setPosition(CP(0.5f, 0.45f));

nameBox->setFont(“Arial”, 42.0f);

nameBox->setLabelAnchorPoint(Point(-0.1f, 0.5f));



Note that the classes in libExtensions are located in the cocos2d::extension namespace, and for libNetwork you’d want to look into the cocos2d::network namespace. As an example for libNetwork, in the next section I will show how to send a simple POST request using the HttpRequest and HttpClient classes.

Sending a POST request with Cocos2d-x

To use HttpRequest and HttpClient, you first need to include their header files:s

#include “network/HttpClient.h”

#include “network/HttpRequest.h”

using namespace cocos2d::network;

Now, let’s assume that we want to send some std::string containing our POST data called data to We can use the following code snippet to do that:

HttpRequest* request = new HttpRequest();

request->setUrl(“ “);


request->setRequestData(data.c_str(), data.size());



It’s that easy. Sending GET, PUT and DELETE requests is also very similar, you just need to pass a different HttpRequest::Type to the setRequestType(…) method.

6 thoughts on “Gotchas: Using Cocos2d-x libExtensions and libNetwork

  1. Teijón

    Hi, thanks for this post. I´m getting this error when trying to build all cocos2d projects in Visual Studio 2012:

    LINK : fatal error LNK1104: cannot open file ‘E:adt-androidcocos2d-x-cocos2d-x-3.1.1buildDebug.win32libNetwork.lib’

    1. This probably means that either that library is not being copied to your output folder for linking, or libNetwork is not building. Can you check if you have libNetwork.lib in any of your build folders? If so, try copying it manually to buildDebug.win32 and build again, maybe that will solve the issue…

  2. Hi KRIS, thank for the post, it’s useful. But i got this issue when trying to running my project:
    “Error 9 error LNK1120: 2 unresolved externals ”

    “Error 7 error LNK2019: unresolved external symbol “public: static class cocos2d::network::HttpClient * __cdecl cocos2d::network::HttpClient::getInstance(void)” (?getInstance@HttpClient@network@cocos2d@@SAPAV123@XZ) referenced in function “public: virtual bool __thiscall HelloWorld::init(void)” (?init@HelloWorld@@UAE_NXZ) D:\Softwares\Android\Projects\dailycoding\proj.win32\HelloWorldScene.obj dailycoding”

    “Error 8 error LNK2019: unresolved external symbol “public: void __thiscall cocos2d::network::HttpClient::send(class cocos2d::network::HttpRequest *)” (?send@HttpClient@network@cocos2d@@QAEXPAVHttpRequest@23@@Z) referenced in function “public: virtual bool __thiscall HelloWorld::init(void)” (?init@HelloWorld@@UAE_NXZ) D:\Softwares\Android\Projects\dailycoding\proj.win32\HelloWorldScene.obj dailycoding”

    Hope this can help me. Thank you

Leave a Reply