Error Building C++ Unix Build

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

Espeide
Posts: 7
Joined: 08 Feb 2017, 04:38

Error Building C++ Unix Build

Postby Espeide » 08 Feb 2017, 04:57

Hello,

I have tried several times to build the C++ Client API using the tutorial provided on the documentation, but always end up with errors.

I follow everything the tutorial says, but there are some differences in what I do: there is no Deploy folder to stop from building, when running ./b2 i get 6 .a files instead of 5 and then the following errors when i build it on Eclipse.

Any way you can help me?

(rest of the problems are in the attachments)
http://pasteboard.co/3aLaTPeE4.png

Thank you,
Espeide.
Attachments
Problems.png
(226.02 KiB) Not downloaded yet
aFIles.png
(171.8 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 19630
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Error Building C++ Unix Build

Postby Lapo » 08 Feb 2017, 08:52

Hi,
can you specify what OS you're running (it looks like Ubuntu 16)?
Also what version of Eclipse?

What API version? Is the latest 1.7.x?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Espeide
Posts: 7
Joined: 08 Feb 2017, 04:38

Re: Error Building C++ Unix Build

Postby Espeide » 08 Feb 2017, 09:54

Hello,

My OS is Ubuntu 16.04 (Tried on two machines, same results).

Eclipse version is Kepler Service Release 2 (C/C++ Developers)

API version is indeed the 1.7.0.

Thank you
User avatar
Lapo
Site Admin
Posts: 19630
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Error Building C++ Unix Build

Postby Lapo » 08 Feb 2017, 10:16

Thanks, we're going to setup a similar environment and get back to you.

Stay tuned.
Lapo

--

gotoAndPlay()

...addicted to flash games
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Error Building C++ Unix Build

Postby MBagnati » 12 Feb 2017, 22:35

Hi,
please try these steps:


  • Unzip the attachment align.zip into Core/BoostAsio/Unix/boost
    You must have the align folder obtained from decompression into Core/BoostAsio/Unix/boost as sibling of other existent folders like algorithm, archive, ...
  • Edit file Request/Game/JoinRoomInvitationRequest.cpp
    At row 56

    replace

    Code: Select all

    Init(targetRoom, invitedUserNames, NULL, 30, false);

    with

    Code: Select all

    Init(targetRoom, invitedUserNames, boost::shared_ptr<ISFSObject>(), 30, false);

  • Open the Project settings panel and modify the Miscellaneous settings for Cross G++ Compiler. Add:

    -std=c++11 -pthread

    Please see attached file 01.png for details
  • Open the Project settings panel and modify the Cross G++ Linker section:

    a) add into Library search path

    /lib/x86_64-linux-gnu/


    b) add into Libraries

    pthread
    z

    Please see attached file 02.png for details
Attachments
align.zip
(21.87 KiB) Downloaded 23 times
02.png
(219.67 KiB) Not downloaded yet
01.png
(210.04 KiB) Not downloaded yet
Espeide
Posts: 7
Joined: 08 Feb 2017, 04:38

Re: Error Building C++ Unix Build

Postby Espeide » 13 Feb 2017, 03:52

Hi,

Thank you very much for these steps, I managed to build it successfully.

I'm trying to use it on another project but I cannot seem to make the correct includes paths work

I also tried to run your LoginExample but these errors occurred (http://imgur.com/a/OZI7H).

Could you help me solve these issues?

Thank you.
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Error Building C++ Unix Build

Postby MBagnati » 15 Feb 2017, 10:40

Hi,

The LoginExample project is written for Eclipse on Windows (using MinGW)
It cannot be built in Ubuntu environment
In Ubuntu you can use this sample as guideline to write your own project
Espeide
Posts: 7
Joined: 08 Feb 2017, 04:38

Re: Error Building C++ Unix Build

Postby Espeide » 17 Feb 2017, 03:26

Hello,

Thank you for your help.

I was able to create a Login example in which I can communicate with a Smartfox server, but I have some questions if you could help me.

in the main() function the logic is as folows:
Send a Connect Request to the server (triggers a Login too)
I'm using boost::asio::deadline_timer to wait for the Connecton/Login so I can proceed with sending data.
After each function I use boost::asio::deadline_timer::wait() but this is not good enough for my goal.

Code: Select all

io_Service io;
deadline_timer t

server->Connect();
t.wait();

server->GetInformation();
t.wait();

....



What other functions should I be using, as I want to know when the Connect functions returns so i can continue the execution.
User avatar
Lapo
Site Admin
Posts: 19630
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Error Building C++ Unix Build

Postby Lapo » 17 Feb 2017, 08:40

Hi,
no this is not the way the API work. For every request you send there is a call back (event) that will be called by the server when it replies.
You don't have to create timers and wait, just register for each event.

For example you need to listen the SFSEvent::CONNECTION event, which will notify if the connection was successful:

Code: Select all

sfs->AddEventListener(SFSEvent::CONNECTION, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(OnConnection, (unsigned long long)this)));

// ...

void OnConnection(unsigned long long context, boost::shared_ptr<BaseEvent> evt)
{
   // Get connection result
   boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = evt->Params();
   boost::shared_ptr<void> ptrEventParamValueSuccess = (*ptrEventParams)["success"];
   boost::shared_ptr<bool> ptrError = ((boost::static_pointer_cast<bool>))(ptrEventParamValueSuccess);

   if (*ptrError)
   {
      // Connection established
      cout << "Connection established and handshake completed with success" << endl;

      // Send login...
   }
   else
   {
      cout << "Connection Failed" << endl;
   }
}


I would highly recommend to take a look at the examples provided in the C++ Example package:
http://smartfoxserver.com/download/sfs2x#p=examples

In particular take a look at the first couple of examples, such as the "Connector" example. It shows the very basics of creating the client instance, setting up the event listeners and connecting and logging into the server.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
Espeide
Posts: 7
Joined: 08 Feb 2017, 04:38

Re: Error Building C++ Unix Build

Postby Espeide » 21 Feb 2017, 08:44

Hello,

I was able to finish the compilation and already have a working project.

I'm currently trying to move the project to my raspberry Pi but I am encountering a strange error and can't find a suitable solution.

http://imgur.com/VYcYfJ2

I am able to run the make all command until that point.

I also tried to run the ./boostrap and ./b2 commands to generate new files but the same error occurs.

Thank you
User avatar
Lapo
Site Admin
Posts: 19630
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Error Building C++ Unix Build

Postby Lapo » 21 Feb 2017, 11:26

Hi,
what OS are you running on the Raspberry Pi?

From the screenshot it looks like the Boost libs compiled correctly, but the "make all" step is not part of our Linux build instructions:
http://docs2x.smartfoxserver.com/Gettin ... clipse-nix

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Espeide
Posts: 7
Joined: 08 Feb 2017, 04:38

Re: Error Building C++ Unix Build

Postby Espeide » 22 Feb 2017, 02:30

Im running Ubuntu Mate, 16.04.

The problem is, even though is says they compiled successfully, the *.so are 0Kb in size (while the .a and .so.1.59.0 seem to be ok).
And the makefile only looks for these files as libs, nothing else, that's why I asked if I could do something different.

I tried this soltuion (to force an arm compile), but without success.
http://stackoverflow.com/questions/2902 ... tu-for-arm
Espeide
Posts: 7
Joined: 08 Feb 2017, 04:38

Re: Error Building C++ Unix Build

Postby Espeide » 22 Feb 2017, 03:55

Hello,

I was able, using some change to the jam file, to create .so files for the boost library and when i ran my Makefile they do not give errros.

But the "libSmartFoxClientApi" file is giving the same error: file not recognized: File format not recognized.

I think its because I was able to compile the boost files to ARM but i did not compile the SmartFoxApi to ARM.
With the steps in the website am I able to compile in ARM architecture?
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Error Building C++ Unix Build

Postby MBagnati » 09 Mar 2017, 08:41

Hi,
I do not know Raspberry Pi, but reading your sentences I think that the "File format not recognized" problem is due to a different target architecture selected to build your application and to build SmartFoxClientAPI library

I reading that you are working with Eclipse Kepler in Ubuntu; have you installed ARM toolchain (for instance dowloading it from https://launchpad.net/gcc-arm-embedded) ?

If you have it, which problems do you find to build SmartFoxClientAPI with ARM toolchain? Have you any compiler or linker error?

Theoretically the same API build instructions for the Eclipse environment can be used for ARM platform; should be only a question of toolchain selection

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 1 guest