Solution for connecting libpomelo to the Cocos2d-x on Mac

Source: Internet
Author: User
Abstract: Use GYP to connect libpomelo to a Cocos2d-x project and enable a successful connection between the project and the server. Configuration: OSX10.9.4Xcode6.0Cocos2d-x-3.2 Method 1: cn. cocos2d-x.orgtutorialshow? Id1561 1. Deploy GYP (GenerateYourProjets) 1. Download The GYP project terminal and go to the project where you want to install GYP.

Abstract: Use GYP to connect libpomelo to a Cocos2d-x project and enable a successful connection between the project and the server. Configuration: OS X 10.9.4 Xcode 6.0 Cocos2d-x-3.2 Method 1: http://cn.cocos2d-x.org/tutorial/show? Id = 1561 1. Deploy GYP (Generate Your Projets) 1. Download The GYP project terminal and go to the project where you want to install GYP.

Abstract: Use GYP to connect libpomelo to a Cocos2d-x project and enable a successful connection between the project and the server.

Configuration: OS X 10.9.4 + Xcode 6.0 + Cocos2d-x-3.2

Method 1: http://cn.cocos2d-x.org/tutorial/show? Id = 1561

1. Deploy GYP (Generate Your Projets)

1. Download The GYP Project

Terminal to the directory where you want to install the GYP project, execute the following command:

1

$ svn checkout http://gyp.googlecode.com/svn/trunk/ gyp-read-only

You can also download: gyp.zip


2. Switch the terminal to the root permission

1

$ sudo -i

Enter the user password of the Local Machine (that is, the computer login password) after you press Enter ). No visual feedback (no asterisks are displayed ).


3. Go to the GYP project directory and perform setup

1

$ ./setup.py install


Ii. Deployment of libpomelo

1. Download The libpomelo Project

1

$ git clone https://github.com/NetEase/libpomelo.git

You can also download: libpomelo-master.zip


2. Generate the libpomelo Xcode Project

Compile Mac

1

2

$ ./pomelo_gyp

$ xcodebuild -project pomelo.xcodeproj

Compile iOS

1

2

$ ./pomelo_gyp -DTO=ios

$ ./build_ios

Compile iOS Simulators

1

2

$ ./pomelo_gyp -DTO=ios

$ ./build_iossim


  • Possible Errors

Q | error message:

Xcodebuild: error: SDK "iphonesimulator6.1" cannot be located.

A | solution:

Open the build_iossim file and change the Simulator version to the required version.


3. Compile and run the libpomelo Xcode Project

Open the generated pomelo. xcodeproj file and compile and run it.


4. Package static library files

After compiling libpomelo, several static library files are generated. If you want to develop multiple platforms at the same time, you can package static library files of the same name for different platforms.

There are three types of static library files generated by compilation, which are placed in subfolders of the following folders:

  • Libpomelo-> libpomelo. a under build

  • Libpomelo-> deps-> jansson-> libjansson. a under build

  • Libpomelo-> deps-> uv-> libuv. a under build

For example, the directory structure of the libpomelo. a file is as follows:

You can use the following command to combine the two selected blue files in the image into a new path.

1

$ lipo -create [filePath1] [filePath2] -output [pathOfNewFile]

The effect of static library file packaging is as follows:


5. Delete libpomelo

Create a new lib folder in the project to unify the static library files. For other parts of the project, you only need to keep the following folder files:

  • Libpomelo-> include

  • Libpomelo-> deps-> jansson-> src

  • Libpomelo-> deps-> uv-> include

An example of the processed directory structure is as follows:

3. Import static library into Cocos2d-x Project

1. Create an Cocos2d-x Project

For the creation of Cocos2d-x project, refer to the development environment of Cocos2d-x v3.2 under Mac.


2. Add libpomelo to your Cocos2d-x Project

In XCode, right-click the project, Add Files to "XXX", and click Add libpomelo Folder:

3. Add static library files

Click the Target of the project, select the Build Phases tab, and find Link Binary With Libraries,

Click +, click Add Other ...,

Add the three static files in the imported libpomelo project.

4. Add a header file search path

Switch to the Build Settings tab, find the Search Paths entry, and add three items to the User Header Search Paths and Library Search Paths respectively, which are include under the libpomelo folder, deps-> jansson-> src and deps-> uv-> include absolute paths of these three folders.


You can add the following three rows in relative paths:

  • $ {PROJECT_DIR}/libpomelo/include

  • $ {PROJECT_DIR}/libpomelo/deps/uv/include

  • $ {PROJECT_DIR}/libpomelo/deps/jansson/src

$ {PROJECT_DIR} is the environment variable provided by Xcode and represents the path of the project.

Tip: to obtain the absolute path of a folder, first open the folder in the project with Finder, and then drag the folder to the terminal.


5. Add the library file search path

Similarly, in the Search Paths entry, locate the Library Search Paths item and add the preceding three Paths.


Iv. Verification

Add a piece of code in the project to verify that libpomelo has been installed successfully. In this example, the server is chatofpomelo-websocket.


1. Run the server

1) download chatofpomelo-websocket

1

$ git clone https://github.com/NetEase/chatofpomelo-websocket.git

2) install Dependencies

1

$ sh npm-install.sh

3) run game-server

Go to the game-server folder under the chatofpomelo-websocket project on the terminal. Run:

1

$ node app


2. Run the client

1) Add a header file

Add the header file to the HelloWorldScene. cpp file.

1

#include "pomelo.h"


2) Add test code

Add the following code to the init () function:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

/* Request a connection from the server */

const char * ip = "127.0.0.1";

int port = 3014; // The Connection port number provided by the server chatofpomelo-websocket for the client.

pc_client_t * pClient = pc_client_new();

struct sockaddr_in address;

memset(&address,0,sizeof(struct sockaddr_in));

address.sin_family = AF_INET;

address.sin_port = htons(port);

address.sin_addr.s_addr = inet_addr(ip);

if (pc_client_connect(pClient, &address))

{

CCLOGINFO("***** Connection Failed! *****");

pc_client_destroy(pClient);

}

else

{

CCLOGINFO("***** Connection Succeed! *****");

pc_client_destroy(pClient);

}

For more information about the code, see pomelo client development.


3) Compile and run the project

If cocos2d is output in output after running the project: ***** Connection Succeed! * ***** Indicates that libpomelo is successfully configured.

  • Possible Errors

Q | error message:

Undefined symbols for architecture x86_64:

"_ FSEventStreamCreate ",

Referenced from: _ uv _ fsevents_init in libuv. a (fsevents. o)

"_ FSEventStreamInvalidate ",

Referenced from: _ uv _ fsevents_close in libuv. a (fsevents. o)

"_ FSEventStreamRelease ",

Referenced from: _ uv _ fsevents_close in libuv. a (fsevents. o)

"_ FSEventStreamScheduleWithRunLoop ",

Referenced from: _ uv _ fsevents_schedule in libuv. a (fsevents. o)

"_ FSEventStreamStart ",

Referenced from: _ uv _ fsevents_schedule in libuv. a (fsevents. o)

"_ FSEventStreamStop ",

Referenced from: _ uv _ fsevents_close in libuv. a (fsevents. o)


Ld: symbol (s) not found for architecture x86_64

Clang: error: linker command failed with exit code 1 (use-v to see invocation)

A | solution:

For Mac, add

-Framework CoreFoundation

-Framework CoreServices

For iOS, you do not need to add the above Flags.


Reference Source: Libraries to compile libuv on OS X


V. Reference Links

1. Compile libpomelo static library under Mac and reference it in Cocos2d-x Project (very detailed explanation, rich text)

2. libpomelo official README document (great reference value)

3. pomelo client Development (also an official document and a Chinese version of link 2)

4, Mac Cocos2d-x connected to the pomelo server (write more concise, write the necessary parts)

5. migrate to Mac (if there are some unexpected situations, you can try to refer to it. The value of this article is relatively low)

6. Teach you how to add libpomelo client components to Cocos2d-x 3.0 Project (Windows, Android, iOS platform) (official documentation, add components in another way, relatively cumbersome)


Source: http://www.cnblogs.com/tangyikejun/p/3988724.html

Method 2: http://www.cnblogs.com/yangxq/p/3791682.html

Recently, cocos2dx needs to interact with the server, so I have been learning how to compile and use libpomelo static libraries over the past few days. Previously, libpomelo was compiled in windows and introduced smoothly in VS. However, it takes more time to get familiar with Mac and XCode. However, I finally succeeded. Here I will record the process of compiling and introducing libpomelo to the static library and share it with my friends who have encountered the same problems.

Preparations

Libpomelo: Batch

At this point, we need to use gyp to generate and compile the project file. It is very slow to download gyp from the official website. This is what I downloaded from other places and I will share it with you.

Install gyp now. You can see that setup. py should know that this python file is related to installation. Use the help command to view the relevant information and find that the build and install commands can be used for compilation and installation.

Compile

During installation, due to permission issues, you must add the sudo command to enhance the permission and enter the password.

After the gyp is successfully installed, our preparations are ready.

Compile static library

Run the following command on the terminal:

  ./pomelo_gyp -DTO=ios  ./build_ios  ./build_iossim

First, go to the downloaded libpomelo directory, and then compile the static library of the ios device.

Static library compiled!

Next, compile the static library of the ios virtual machine.

An error occurs because I have not installed the IOS6.1 Virtual Machine in xcode. Click the Preferences menu under xcode and switch to the Downloads tab.

I have not waited for the installation to complete. I directly switch to another system with a virtual machine installed. "√" indicates that the system has been installed.

Re-compile now, compilation successful

Now we can view the static library files generated by compilation.

Libpomelo-> build:

Libpomelo-> deps-> jansson-> build:

Libpomelo-> deps-> uv-> build:

At this time, the static library file has been compiled successfully, a total of 6. a files.

Package static library files

Run the following command on the terminal:

Lipo-create File 1 file 2-output New File

We can package static libraries of ios devices (arm) and ios virtual machines (i386) with the lipo command for our convenience.

After the preceding command is entered, three packaged. a files are generated in the libpomelo directory.

Now, we can use these three static libraries in the project.

Next, extract the required static library and related header files. Save the files in the libpomelo-> include folder, libpomelo-> deps-> jansson-> src folder, libpomelo-> deps-> uv-> include folder, and 3 files. file a is stored in the new directory lib. The final directory structure is as follows:

Cocos2dx project introduces static library

Add the directory containing the static library and header file to the project. In XCode, right-click the project and choose "Add Files to XXX", select the directory above, and Add

Now we can see the newly added directory in our project.

Click the Target of the project, select the "Build Phases" tab, and find "Link Binary With Libraries"

Click "+" and then "Add Other ...", Select three static databases and click Open.

The static library has been added to the project.

Now, switch to the "Build Settings" tab, find "Search Paths", and add three items in "Header Search Paths" and "Library Search Paths", which are include in libpomelo, deps-> jansson-> src and deps-> uv-> include physical paths.

Close XCode, re-open the project, and compile. An error is reported in "jansson. h ".

We will change the angle brackets here to quotation marks, and "hashtable. c" will also be processed, re-compiled, and compiled successfully.

Now we can use the services provided by the libpomelo library in the project.

First, we introduce the header file # include "pomelo. h" in AppDelegate. cpp, and then compile the file. At this time, an error occurs in "map. h ".

Change it to # include "ngx-queue.h" can be, re-compilation, compilation successful!

I believe everyone can solve these header file references (You may encounter different problems than me, but they should all be minor issues ).

Connect to the pomelo Server

Add the following code to the program:

After the compilation is successful, run the program and the console output is as follows. In this case, the connection fails because there is no server.

Next, open the pomelo server in the vmvm and activate it. Then, enter the ip address and port in the MAC browser to check that the server is active (the server code I used is https://github.com/netease/chatofpomelo-websocket, of course, the ip address and port in the Code are modified)

Run our program again. The console output is as follows:

So far, we have successfully compiled the libpomelo static library, introduced it into the project, and tested the connection to the pomelo server!

NOTE 3: http://blog.csdn.net/hsyj_0001/article/details/9751819

Recently I heard that the open-source game server framework of pomelo is good, and the documentation is quite detailed (this is all about, in fact... let's take a look at it later), so I used it for research. Because of the iphone game, I plan to install it on Mac OS X. According to the official documentation guide, pomelo has finally been installed successfully, except for node. js has encountered some accidents during the installation process, but it is still relatively smooth.

Next, when installing the libpomelo library on the client, you will find a wide variety of questions based on the official address https://github.com/netease/libpomeloprompt. As an open-source product, it can only be compiled and installed by others. How can it be expanded.

First, the official system prompts you to install GYP. What is GYP? Why? Where can I download it? How to install?

Download the GYP from the GYP link.

[Plain]View plaincopy

  1. Svn checkout http://gyp.googlecode.com/svn/trunk/ gyp-read-only


Go to the gyp-read-only directory, but still do not know how to install it. /setup. py -- help to view help information and learn about it. /setup. py build can be compiled and then executed. /setup. py install can be installed. But execute. /setup. the error:/usr/local/bin/gyp: Operation not permitted will be prompted during py install. Due to the current user permission issue, you need to re-Execute sudo. /setup. py install can be successful.

Next, we will officially compile the libpomelo library. First, run the git clone https://github.com/netease/libpomelo.gitcommand to download the source code. (If the git command is built-in in the Mac system, install it in windows ). Run the cd libpomelo command to go To the downloaded source code directory and compile the library in the ios environment according to the official guide. /pomelo_gyp-DTO = ios, but the following error message is displayed: python: can't open file '/usr/local/bin/gyp_main.py ': [Errno 2] No such file or directory, which is obviously because the gyp_main.py file is not successfully installed during GYP installation. So according to some solutions on the internet, I copied the GYP directory to the libpomelo directory and then executed it. /gyp-read-only/gyp -- depth =. pomelo. gyp-Dlibrary = static_library-DTO = ios, finally built successfully. In fact, this command is actually the content in pomelo_gyp, but due to directory level issues, I simply execute it outside.

Follow the instructions in the Guide. /build_iossim found an error when compiling the static library, but the specified sdk6.1 was not found. Therefore, there were no solutions to various Baidu-based Google on the Internet, the only solution that has encountered a similar problem is to compile it on other XCode5 machines. This solution is not completely scientific. Therefore, run the pico build_iossim command to open the compilation configuration file to see why. The original compilation parameter-the version specified by sdk iphonesimulator6.1 is too high in my development environment. I only use sdk 5.0 locally, therefore, change all 6.1 in this file to 5.0 and then execute Ctrl + X to exit the compilation status and then execute. the/build_iossim command can be compiled successfully.

It is hard to imagine that a product such as Netease has been doing so simply. In addition to the ability of developers to build a development environment and diagnose problems, for example, it is difficult for developers who have just started to get started.

We recommend that NetEase improve the environment construction manual and Development Manual. The document is not intended for users, but for developers who do not have access to these products. Therefore, we must put ourselves in the perspective of the Creator, you can even think of a developer with zero base, step-by-step to guide development, so as to better promote this product.

Later, take the time to add libpomelo to the Project of the cocos2d-x and try to call communication between the client and the Server.

Tutorial connection:

Http://www.cnblogs.com/yangxq/p/3791682.html

Https://github.com/NetEase/pomelo/wiki/pomelo%E5% AE %A2%E6%88%B7%E7% AB %AF%E5%BC%80%E5%8F%91

Http://cn.cocos2d-x.org/tutorial/show? Id = 1561

Https://github.com/NetEase/pomelo/wiki/Home-in-Chinese

, Mac to compile libpomelo static library, and reference in the Cocos2d-x Project (very detailed explanation, rich text)

2. libpomelo official README document (great reference value)

3. pomelo client Development (also an official document and a Chinese version of link 2)

4, Mac Cocos2d-x connected to the pomelo server (write more concise, write the necessary parts)

5. migrate to Mac (if there are some unexpected situations, you can try to refer to it. The value of this article is relatively low)

6. Teach you how to add libpomelo client components to Cocos2d-x 3.0 Project (Windows, Android, iOS platform) (official documentation, add components in another way, relatively cumbersome)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.