icculus / Serious-Engine

An open source version of a game engine developed by Croteam for the classic Serious Sam games.
GNU General Public License v2.0
164 stars 21 forks source link

Export symbols of main executable to dynamic libs #20

Closed stevenc99 closed 8 years ago

stevenc99 commented 8 years ago

Link the main executable with -rdynamic, so that its symbols are available for dynamic objects (such as libEntitiesMPD.so) to use.

I'm not sure why only I had this problem, and you're not seeing it.

I'm using GNU toolchain in Debian jessie amd64, GCC 4.9.

-rdynamic is quite portable, Clang also understands it since at least version 3.3. It should cause no harm to add this in any case? (this is in inside a cmake if(LINUX) block).

Without -rdynamic, the game would fail to start with: CUnixDynamicLoader error: Bin/Debug/libEntitiesMPD.so: undefined symbol: _ZN7CEntity21SetPlacement_internalERK12CPlacement3DRK6MatrixIfLi3ELi3EEi

This refers to a function defined in Engine/Entities/Entity.cpp.o: CEntity::SetPlacement_internal(CPlacement3D const&, Matrix<float, 3, 3> const&, int) which is linked into Bin/Debug/ssam, but for me it was not exported as a dynamic symbol without setting this linker flag.

Thanks again!

ericwomer commented 8 years ago

Would that work with static libs also? so we could make libEngine.a again?

stevenc99 commented 8 years ago

I can't see any reference to libEngine.a in the source, so I'm not sure what that is exactly. -rdynamic probably has no effect if using a ".a" archive; there is an equivalent "-Wl,--whole-archive" linker flag for those, to do the same thing).

icculus commented 8 years ago

Weird, Cmake already forces rdynamic for me. I'm okay with this change, but first, add a commit to do this for the dedicated server executable too, please.

stevenc99 commented 8 years ago

I looked into why my CMake behaviour might differ from yours, and found this: https://cmake.org/cmake/help/v3.4/policy/CMP0065.html so, thanks for mentioning it!

It mentions CMake property ENABLE_EXPORTS. That will set -rdynamic (or -Wl,--export-dynamic) for executables marked with it, if the platform requires it and the toolchain supports either of those flags.

I've updated the commit in my pull request with that, also adding it for SeriousSamDedicated this time.

I now understand Rake's question about libEngine.a; I'm still not sure if ENABLE_EXPORTS will work for that, but it certainly won't cause harm to have it.

Great work by the way, I had an amd64 build running with SDL2 today. Thanks!

ericwomer commented 8 years ago

Yeah sorry about the confusion, ryan wanted a static lib for the engine, instead of having it basically built twice, once with client, and once with server, but it was dropping symbols when linking.

stevenc99 commented 8 years ago

I can already build the game and dedicated server at the same time? Just with the diff from https://github.com/rcgordon/Serious-Engine/pull/22

icculus commented 8 years ago

Yeah, the game and server build without -rdynamic, but dlopen()ing the game library at runtime fails because it needs symbols in the main binary.