heroiclabs / nakama-cpp

Generic C/C++ client for Nakama server.
https://heroiclabs.com/docs/cpp-client-guide
Apache License 2.0
69 stars 25 forks source link

Compile with position independent code enabled #14

Closed opcon closed 5 years ago

opcon commented 5 years ago

Hi,

First of all, thanks for making this library! I've been writing a Godot GDNative wrapper for Nakama https://github.com/opcon/nakama-godot, which compiles into a shared library.

To do this, the nakama-cpp libraries need to be compiled with position independent code (-fPIC). I've made this change locally, and everything is working.

Is it possible to compile the released versions of nakama-cpp with -fPIC?

I don't know enough about C++ to know if this has performance/other implications.

Cheers :)

Dimon4eg commented 5 years ago

Hi @opcon ! If you build nakama-cpp as shared lib then it should be enabled by default in CMake: https://cmake.org/cmake/help/latest/prop_tgt/POSITION_INDEPENDENT_CODE.html

Why do you need nakama-cpp to be shared lib?

opcon commented 5 years ago

Hi @Dimon4eg,

I'm referring to the prebuilt (linux) libraries on the Releases tab - at the moment I can't use those as is because they are not compiled with -fPIC. Would you accept a pull request that builds the static version of nakama-cpp with position independent code enabled by default?

I am compiling the static nakama-cpp libraries with some Godot-specific wrapper code into a single shared object file (nakama-godot.so), which is then loaded by Godot at runtime.

Dimon4eg commented 5 years ago

I see. Then we should distribute two variants: without -fPIC and with -fPIC. Here is explanation: https://stackoverflow.com/questions/37842036/why-does-including-fpic-to-compile-a-static-library-cause-a-segmentation-fault

Before sending PR could you please add this to beginning of nakama-cpp/CMakeLists.txt: set(CMAKE_POSITION_INDEPENDENT_CODE ON) And check does it work for you? Is this needed only on Linux?

opcon commented 5 years ago

Hi @Dimon4eg,

As of the 2.0.3 release, this is no longer an issue, as I can use the shared library instead.

Thanks