serverplugin_empty under linux

Problem

serverplugin_empty_i486.so is compiled, but Source Linux dedicated server rejects to dynamically link it. I finally found the solution, and write it here for who share the trouble!

If you do not know what is serverplugin_empty_i486.so, you must not waste your time to read this page! Just go back to your happy game!

Observation

Check what kind of libraries are linked to the so:
~/mymod/linux_sdk$ ldd -d serverplugin_empty_i486.so 
undefined symbol: _Z12MathLib_Initfffibbbb (./serverplugin_empty_i486.so)
undefined symbol: _Z10Bot_RunAllv (./serverplugin_empty_i486.so)
linux-gate.so.1 => (0xffffe000)
libm.so.6 => /lib/tls/libm.so.6 (0xb7f51000)
libdl.so.2 => /lib/tls/libdl.so.2 (0xb7f4d000)
tier0_i486.so => ./tier0_i486.so (0xb7f1b000)
vstdlib_i486.so => ./vstdlib_i486.so (0xb7f06000)
libc.so.6 => /lib/tls/libc.so.6 (0xb7dce000)
/lib/ld-linux.so.2 (0x80000000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0xb7dbb000)
Like above, the sample Makefile does not link enough object and dll files. As a result, there are two missing symbols which make dynamic-linking fails.

Fix1: _Z10Bot_RunAllv

This one is easy. Makefile.plugin misses to build and link serverplugin_bot.o. Fix it:
PLUGIN_OBJS = \
$(PLUGIN_OBJ_DIR)/serverplugin_convar.o \
$(PLUGIN_OBJ_DIR)/serverplugin_empty.o \
$(PLUGIN_OBJ_DIR)/serverplugin_bot.o \

Fix2: _Z12MathLib_Initfffibbbb (and _Z12AngleVectorsRK6QAngleP6Vector)

Only with Fix1, you still have missing symbols _Z12MathLib_Initfffibbbb and _Z12AngleVectorsRK6QAngleP6Vector. This is since the plugin still needs one more dll from the dedicated server in addition to tier0_i486.so and vstdlib_i486.so. You can find the dll by:
nm --print-file-name .../bin/*so | grep MathLib_Initfffibbb
You will find bunch of .so dlls which define the symbol. I am not sure which one is the best, but I use dedicated_i486.so. Now modify Makefile (not Makefile.plugin):
# link flags for your mod, make sure to include any special libraries here
# LDFLAGS="-lm -ldl $(GAME_DIR)/bin/tier0_i486.so $(GAME_DIR)/bin/vstdlib_i486.so"
LDFLAGS="-lm -ldl tier0_i486.so vstdlib_i486.so dedicated_i486.so"
Of course I made a symbolic link of dedicated_i486.so at the build directory and set LD_LIBRARY_PATH so that the linking goes successful.

Conclusion

Good luck!