SFS2X Docs / GettingStarted / client-api-cpp-macos-xcode7
» Client API setup | C++
» macOS — Xcode 7 and higher
» Libraries compilation
To compile the required libraries, please check that you are using at least the release 1.59 of Boost.
Launch a Terminal on the file system path [api_folder]/Core/BoostAsio/Unix and type in the command chmod -R a+rwx+X ./
Now type in: ./bootstrap.sh –prefix=boost/ and wait for the command execution.
When completed, type in: ./b2
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 the built libraries.
The Terminal can now be closed.
Start Xcode and create an OS X Dynamic Library project for STL C++
Add all SmartFox API folders and files to the created project.
Now remove the Core/BoostAsio, Core/OpenSSL and ZLib references from the project (NOTE: just remove the references, do not the delete the actual folders)
This is what the project view should look like after having removed the three items in the previous step:
Under Build Settings:
- add under Preprocessor Macros the value: SMARTFOXCLIENTAPI_EXPORTS
- add under Preprocessor Macros the value: BOOST_THREAD_PROVIDES_FUTURE
- turn off the Precompiled Header Uses Files From Build Directory setting
- set Header Search Paths to [api_folder]/Core/BoostAsio/Unix
- aet Header Search Paths to /usr/local/openssl-1.0.2k/include (replace with your path if different)
NOTE: the position of the openssl library depends on the package manager used to install on your Mac. You can use Brew or MacPorts to setup the latest OpenSSL libraries. Then make sure to reference the correct path based on the location used by the tool of your choice.
Alternatively you can download the OpenSSL sources from the official website and compile it.
Firstly decompress the archive, open a terminal in the unpacked folder and type:
- sudo mkdir -p /usr/local/openssl-1.0.2k
- ./Configure darwin64-x86_64-cc --prefix=/usr/local/openssl-1.0.2k
- make
- sudo make install
- set Library Search Paths to [api_folder]/Core/BoostAsio/Unix/stage/lib
- set Library Search Paths to /usr/local/openssl-1.0.2k/lib (replace with your path if different)
Add the following paths to the Prelink libraries menu
- /usr/local/openssl-1.0.2k/lib/libcrypto.a
- /usr/local/openssl-1.0.2k/lib/libssl.a
- [api_folder]/Core/BoostAsio/Unix/stage/lib/libbost_thread.a
- [api_folder]/Core/BoostAsio/Unix/stage/lib/libbost_system.a
Set Perform Single-Object Prelink to Yes.
Set Other Linker Flags to -lz.
You can now build the SmartFoxServer 2X API and use it in your project.
» Setting up an SFS2X project
Move to the project settings of your Xcode client application. Select the topmost node from the Project Navigatorand select Build Settings.
Under Header Search Path add:
- [SFS2X-API-Folder]/Boost-Unix/
- [SFS2X-API-Folder]/
Under Library Search Path add:
- [Compiled-API-Folder]/
- [SFS2X-API-Folder]//Boost-Unix/stage/lib/
where [Compiled-API-Folder] is the path where you have stored the static API library file.
Under Other Linker Flags add -lz
Finally click on Build Phases in the top bar, select Link Binary with Libraries and add the API compiled .a file.