SFS2X Docs / GettingStarted / client-api-cpp-linux-eclipse
» Client API setup | C++
» Linux/Unix — Eclipse
» Libraries compilation
To compile the required libraries you need Eclipse with C/C++ Development Tools and g++ installed on your computer.
For example, to install g++ on Ubuntu Linux, open a Terminal shell and type the command:
$ sudo apt-get install build-essential g++
You should get the following output:
For other platforms please referer to their documentation.
C++ API needs of Boost and OpenSSL libraries. These are open source packages that can be installed and built by following commands.
In the Terminal shell type in:
$ sudo apt-get install libssl-dev
Then type the following command (use the proper path) to move to the [api_folder]/Core/BoostAsio/Unix folder.
$ cd .../[api_folder]/Core/BoostAsio/Unix
Now type in:
$ chmod -R a+rwx+X ./
and:
$ ./bootstrap.sh –prefix=boost/
and wait for the command execution. When completed, type in:
$ ./b2
You should get the following output:
If all has been done with success, you will find out that a new directory named [api_folder]/Core/BoostAsio/Unix/stage/lib has been created, containing six .a files.
The shell can now be closed.
» API compilation
Start Eclipse and choose File > New > Project from its menu. In the New Project wizard dialog, choose C++ Project from C/C++ section, than press Next.
In the C++ Project dialog:
- set a project name, for instance SmartFoxClientApi;
- remove the flag Use default location;
- browse the file system to set the folder [api_folder] as Location;
- select Empty Project from Shared Library section as Project type;
- select Cross GCC as Toolchains;
Then press Next in all the dialogs until the Finish button is displayed, and press it.
Eclipse will create the SmartFoxServer2X C++ API project.
In the Project Explorer panel, perform the following exclusions (to do it, right-click on the project node and select Resource configuration > Exclude from build or Properties in the popup menu):
- exclude BoostAsio project node from the build for both Debug and Release configurations (located under the Core node);
- exclude OpenSSL project node from the build for both Debug and Release configurations (located under the Core node);
- exclude SmartFoxClientApi project node from the build for both Debug and Release configurations;
- Exclude all subfolders of Zlib project node from the build for both Debug and Release configurations.
Enter the Project settings panel and apply the following changes to C/C++ Build > Settings:
- Set Position Independent Code flag under Cross GCC Compiler > Miscellaneous;
- Set Position Independent Code flag under Cross G++ Compiler > Miscellaneous;
- Add -std=c++11 -pthread flags under Cross G++ Compiler > Miscellaneous;
- add SMARTFOXCLIENTAPI_EXPORTS to the Defined symbols under Cross G++ Compiler > Preprocessor;
- add BOOST_THREAD_PROVIDES_FUTURE to the Defined symbols under Cross G++ Compiler > Preprocessor;
- browse the file system to include the path [api_folder]/Core/BoostAsio/Unix/ under Cross G++ Compiler > Include paths;
- browse the file system to include the path [api_folder]/Core/OpenSSL/Unix/include/ under Cross G++ Compiler > Include paths;
- add boost_thread under Cross G++ Linker > Libraries;
- add boost_system under Cross G++ Linker > Libraries;
- add ssl under Cross G++ Linker > Libraries;
- add crypto under Cross G++ Linker > Libraries;
- add z under Cross G++ Linker > Libraries;
- add pthread under Cross G++ Linker > Libraries;
- set the library search path to [api_folder]/Core/BoostAsio/Unix/stage/lib;
- set the library search path to /Lib/x86_64-linux-gnu;
- set the library search path to /usr/lib/ssl.
Finally, select the menu item Project > Build project to perform a rebuild and generate the SmartFoxClientApi library.
» Setting up an SFS2X project
This section applies only if you're using Eclipse as the iDE for your C++ application/game. If not, please check the documentation of your environment of choice on how to import external libraries.
In Eclipse, move to the project settings of your Eclipse client application. Select Includes under Cross G++ Compiler and add a reference to [api_folder]/Core/BoostAsio/Unix path for both Debug and Release configurations.
Finally move to the Libraries settings ofCross G++ Linker to add the [api_folder]/Core/BoostAsio/Unix/stage/lib path and the output directory where the previously compiled API was deployed. Also addboost_system, pthread and SmartFoxClientApi as application libraries. Perform these steps for both Debug and Release configurations.
You can now start using the SmartFoxServer 2X API in you project.