Hi all, I am trying to compile a statically linked minetestserver to see if I can deploy it on a platform where I do not have much control over what is and what is not installed. FYI the platform is OpenShift and I was thinking of creating a minetest cartridge, possibly with another cartridge running redis. Anyways, platform aside, rather than satisfying all dependencies manually (uploading the .so's and putting them somewhere the dynamic linker can find them), I thought I'd give it a try to compile and statically link the executable on a local Ubuntu VM first.
Some of the things I did and found out sofar:
- I am compiling on a local Ubuntu VM under my control so that I could apt-get all the dependencies, compile and then upload the statically linked executable to the cartridge
- Statically linking *everything* causes a segfault on startup, not even a --version works. Stack trace points to it immediately crashing at pthread get_id. Some googling points out libpthread has issues when statically linked
- I will therefore try to link most common libraries (things like stdc++, pthread, etc.) dynamically, the less common ones (hiredis, cURL, irrlicht, etc.) statically
- To do this I will probably need to tinker with the ld arguments and pass something like -Wl,-Bdynamic -lpthread -letc. -Wl,-Bstatic to the linker
- I found some stuff on StackOverflow talking about passing/ setting CMAKE_FIND_LIBRARY_SUFFIXES to ".a" and setting CMAKE_EXE_LINKER_FLAGS to something like "-static-libblabla -static-libetcetc" for CMake, which will probably then result in the correct arguments being passed to ld
Before I venture any further and possibly spending a lot of time fiddling around, I thought I'd ask around here first: Has anyone tried this before or would anyone have some idea what flags I could pass to CMake/ how to update the CMakeFiles.txt to control the static/ dynamic linking? (I must admit that I am not familiar with CMake, and my C/ C++ programming is a bit rusty these days -_-) Oh, and are there maybe other things that might not behave well when statically linked?
Thanks!