tschumann/sandbot

Static linked libstdc++

Opened this issue · 7 comments

Hey I was wondering do you think it would be better to have the libstdc++ statically linked in Sandbot by using -static-libstdc++ for Makefile Linux? I've not tried this too often but this could help.

I tried to statically link a while ago to sort out a problem but I couldn't figure out how to get it to work.

Well... I did some research for HLSDK and C++ GoldSrc coding and I don't think using newer GCC/G++ compilers later than 4.8 may not be necessary as the GoldSrc engine is ancient and will not be significantly affected by newer Standards as most complex Metamod addons like AMXX appear to use -std=c99. But I had to use -std=gnu++11 (not -std=c++11) for my Metamod addons, as my GCC 4.8 hated the newer code I've converted from NULL to nullptr during when I've been experimenting with recently. Also using GCC 4.8 appears to avoid those "libstdc++ CXX ABI" errors and also compiles the .so binary smaller than the newer GCC. But I don't think using -static-libstdc++ would be necessary for GCC 4.8. Also, I got a few new contacts who would be keen to add support for Sandbot to work better for Op4CTF as JK-Botti hates CTF maps.

So personally I don't think Linux servers for GoldSrc will be affected by performance using GCC 5 or later. However... those Russian HLDM, AG HL, or even Op4 servers appear to use reHLDS to unlock that additional performance boost - which appears more common for those RU servers that use reHLDS along with Metamod-R.

ABI doesn't really matter for the HLSDK, because all the interaction between the engine and the game are via pure C calls, which have standard ABI and the version the the C or C++ standard does not matter.

Regarding static linking of libstdc++, you just need to copy the .a file of the library where the Makefile is located and add -L. to the linker options.

Looking at the Half Life SDK it looks like Valve uses their own build of gcc (which must be based off an old version of gcc, and I guess that's why using a newer gcc gives ABI errors).
I need to get my dev environment for Linux up and running again I tried statically linking libstdc++ (the system one - copying it across to the project felt messy) and I couldn't get it working.

Well I've noticed that this Makefile from HLSDK-am appears to show on linking the libstdc++.

https://github.com/alliedmodders/hlsdk/blob/master/linux/Makefile#L34

Now I've used a Makefile from SoloKiller's HL-OP-Updated Github - that looks almost identical from AlliedMods version- for fixing some of those bugs for Op4CTF, and from what I've gathered from the compile logs in hl_map.txt I think it uses the /usr/lib/gcc/i686-linux-gnu/8/ from my Debian Buster with GCC/G++ 8.3.

Just looking at this again I read this: https://stackoverflow.com/a/54912913
I have no idea if Half-Life and other GoldSource games/mods statically link libstdc++ off the top of my head.

@APGRoboCop have you had any luck with static linking other plugins?