[FIXED] Compilation on Linux seems outdated

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

Moderators: Lapo, Bax, MBagnati

Philou231
Posts: 4
Joined: 18 Jun 2020, 16:34

[FIXED] Compilation on Linux seems outdated

Postby Philou231 » 18 Jun 2020, 16:55

Greetings to the SmartFoxServer team!
First of all, thank you for SFS2X. I am using the C++ API to build communication between computers (rather than using it for an MMO) but I might use it for video games in the future :D

I managed to build the API on Windows with "no" problem. The API works perfectly in my project.
However, I am now trying to build my project on Linux Mint and I am hitting a wall... I carefully followed each step provided in the guide (http://docs2x.smartfoxserver.com/GettingStarted/client-api-cpp-linux-eclipse) but I blocked at the point of compiling the SFS2X Client API. I don't quite know what the problem is so I will let the error messages speak for themselves.

The relevant part is this one:

Code: Select all

Building file: ../Util/CryptoInitializer.cpp
Invoking: Cross G++ Compiler
g++ -DSMARTFOXCLIENTAPI_EXPORTS -DBOOST_THREAD_PROVIDES_FUTURE -I"/home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix" -I"/home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/OpenSSL/Unix/include" -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -pthread -fPIC -MMD -MP -MF"Util/CryptoInitializer.d" -MT"Util/CryptoInitializer.o" -o "Util/CryptoInitializer.o" "../Util/CryptoInitializer.cpp"
In file included from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/OpenSSL/Unix/include/openssl/evp.h:66:0,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/OpenSSL/Unix/include/openssl/x509.h:73,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/OpenSSL/Unix/include/openssl/ssl.h:156,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix/boost/asio/ssl/detail/openssl_types.hpp:20,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix/boost/asio/ssl/context_base.hpp:19,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix/boost/asio/ssl/context.hpp:27,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix/boost/asio/ssl.hpp:19,
                 from ../Util/CryptoInitializer.cpp:18:
/usr/include/x86_64-linux-gnu/openssl/opensslconf.h:20:3: error: #error OPENSSL_ALGORITHM_DEFINES no longer supported
 # error OPENSSL_ALGORITHM_DEFINES no longer supported
   ^~~~~
In file included from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/OpenSSL/Unix/include/openssl/ssl.h:165:0,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix/boost/asio/ssl/detail/openssl_types.hpp:20,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix/boost/asio/ssl/context_base.hpp:19,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix/boost/asio/ssl/context.hpp:27,
                 from /home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/BoostAsio/Unix/boost/asio/ssl.hpp:19,
                 from ../Util/CryptoInitializer.cpp:18:
/home/philou231/Documents/libraries/SFS2X_API_Cpp_v1.7.5/Core/OpenSSL/Unix/include/openssl/kssl.h:72:10: fatal error: krb5.h: No such file or directory
 #include <krb5.h>
          ^~~~~~~~
compilation terminated.
make: *** [Util/CryptoInitializer.o] Error 1
Util/subdir.mk:45: recipe for target 'Util/CryptoInitializer.o' failed
"make all" terminated with exit code 2. Build might be incomplete.


I tried commenting the call to define #OPENSSL_ALGORITHM_DEFINES but the error for the include krb5.h persisted. I tried installing krb5-user, krb5-config and krb5-multidev but without luck. (I have not searched to understand what that is).

My Linux Mint version is 19.3 (Linux Kernel 5.4.0-37-generic)
The SFS2X API Version is 1.7.5
Everything on my system is updated and upgrade to their current version. (I installed linux yesterday)

I am able to compile on linux and I have used it enough to understand the basics (disclaimer, in case I need to do some "technical stuff" to fix the problem)

I am very grateful for this software that you are providing free of charge and any help will be greatly appreciated.
Philou231
Last edited by Philou231 on 11 Jul 2020, 19:33, edited 1 time in total.
Philou231
Posts: 4
Joined: 18 Jun 2020, 16:34

Re: Compilation on Linux seems outdated

Postby Philou231 » 25 Jun 2020, 02:01

Hello again!

I have decided to take a fresh look at the problem today and I have made some progress. There were two errors in my previous log and I have solved one of them. The "fatal error: krb5.h: No such file or directory" was simply a matter of finding the right library. It turns out that it was "libkrb5-dev". I don't know how I missed that on my first look... What matters is that it is solved.

For the second part, the "error: #error OPENSSL_ALGORITHM_DEFINES no longer supported", it is more complicated... I tried simply commenting the only line of code were there is this reference but I don't thing it really solved the problem. The weird thing is that the Client API managed to compile! I tought I had solved the problem but I just kicked the can further down the road.

When I tried to compile my project some errors appeared. "undefined reference to ..." (a list of about two dozen tags, among which: ENGINE_cleanup, EVP_CIPHER_CTX_cleanup, SSLv2_client_method, etc.). This would indicate that I have not linked some library but I did! I linked everything there is to link (I think)... What I think is the problem is the use of an old (the one provided) and a new (the one on my computer) SSL. I feel like there should be an update about this ssl stuff. I am no expert so maybe I made a compiling mistake too...

I would be quite curious to know if someone managed to compile on Linux (debian or derived if possible) recently (last year or so).

As always, thanks a lot for any help that can be provided,
Philou231
Philou231
Posts: 4
Joined: 18 Jun 2020, 16:34

Re: Compilation on Linux seems outdated

Postby Philou231 » 10 Jul 2020, 22:59

It's me again!

I've took another look at the problem today. When linking the OpenSSL library provided in ...Core/OpenSSL/Unix/lib the "undefined reference" errors disapear (obvious) but the linking does not finish either. At first I thought it was a problem during the compilation of the SFS2XClientAPI but when I looked closer I caught the real error in all of this. It turns out that the error is in fact: "lib/x86_64-linux-gnu/libssl.so: file not recognized: file format not recognized". Which is much easier to tackle!

The provided library is not compiled for my system. Hence, it is not recognized properly. (That is my hypothesis but I could be wrong...) My next idea is to recompile SSL to get the proper libssl.so but I lack the source code. By comparing source codes of several old SSL I found a close match, version 1.0.1f. However, the match is not perfect. My question now becomes:

Which version of OpenSSL has been used to compile the libssl.so library for Unix?

Having the closest match will reduce the risks of failed build. In the mean time. I will be trying to compile the version 1.0.1f. I'll report as soon as I have succeeded or more information.

In hope that this monologue will soon turn into a dialogue,
Have a good day,
Philou231
Philou231
Posts: 4
Joined: 18 Jun 2020, 16:34

Re: Compilation on Linux seems outdated

Postby Philou231 » 11 Jul 2020, 19:28

Well...how to put it...IT WORKED! :D
The answer was: build your own (old version of the) OpenSSL library.

The original tutorial (http://docs2x.smartfoxserver.com/Gettin ... ux-eclipse) is pretty close to being perfect. Only minor adjustements need to be made. In case someone tries to build on Linux and encounters the same problems, here are the revised steps:

  1. Execute all the "Libraries compilation" steps to build the Boost library
  2. Fetch the appropriate OpenSSL library from this source: https://ftp.openssl.org/source/old/1.0. ... .2u.tar.gz
    --> Version 1.0.2u is the most recent version that works with the Boost Asio library installed (and/or SFS2X). You could select an older version if needs be
  3. Unzip the OpenSSL library somewhere useful and open a terminal in the extracted folder.
  4. Execute the command "CFLAGS=-fPIC ./config shared"
    --> This command will trigger the configuration of the library for your OS. It will be a shared library (which is what SFS2X needs)
  5. Once the configuration is done, execute the command "make"
    --> This command triggers the actual compilation of the library. Once done, the "libssl.so" file (and friends) will be created in the folder. Feel free to compile any other way if you want the output to be stored elsewhere.
  6. Follow all the steps in the section "API compilation" of the original tutorial without executing the final build.
    --> BTW, when working with Eclipse, by opening the project's properties, you will automatically be in the configuration "Debug". Feel free to change it to "[All configurations]" if you want these changes to be for all cases. Also, you should compile the release version to obtain a lighter version (unless you plan on debugging SFS2X itself...)
  7. In the "Include paths" menu, change "[api_folder]/Core/OpenSSL/Unix/include/" to your newly compiled OpenSSL "include" folder.
  8. In the "Library search path" menu, change "/usr/lib/openssl" to your newly compiled OpenSSL folder (containing libssl.so and other libs)
  9. With these changes you should be good to compile. Start the build!
    --> If you have an error stating "krb5.h: No such file or directory", install "libkrb5-dev"

With all these changes you should have been able to compile the SFS2X C++ Client API! Now comes the time to use the library in one of your projects. If you follow the steps of the original tutorial you should be good but they are not completely accurate. Strangely, I had to change "pthread" for "boost_thread". Also, you need to add the SmartFoxServer's folder to your "Include" since you will include, in one of your source files, the "SmartFox.h" file. There should not be anymore changes needed.

I hope this will help someone else too :)
Philou231
maslas
Posts: 6
Joined: 25 Nov 2019, 07:55

Re: [FIXED] Compilation on Linux seems outdated

Postby maslas » 12 Sep 2020, 14:16

I can confirm that these instructions are correct.
I managed to compile the API and implement it into a cmake project that I am currently working on which belongs to a game engine.

Cheers my friend you are a lifesaver :wink:

By the way and with all due respect the documentation should be revised from time to time, please do not take it as an offense I know that sometimes it is impossible.
User avatar
Lapo
Site Admin
Posts: 21699
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: [FIXED] Compilation on Linux seems outdated

Postby Lapo » 14 Sep 2020, 07:15

Thanks for posting.
Because the C++ API are not part of the official set of API (i.e. they are maintained by a number of volunteers) the documentation got out of synch with the changes that were made, I suppose.

We'll take a look and integrate what Philou231 posted here.

Thanks!
Lapo
--
gotoAndPlay()
...addicted to flash games
maslas
Posts: 6
Joined: 25 Nov 2019, 07:55

Re: [FIXED] Compilation on Linux seems outdated

Postby maslas » 14 Sep 2020, 10:46

Thanks a lot.

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 2 guests