plexinc/plex-home-theater-public — pull request #20 by woodsb02 (2014-11-08 02:17:57+00:00)
Title: ENABLE_EXPORTS: Provide shared libraries access to the functions in the main program

This fixes an error experienced on FreeBSD where PlexHomeTheater would crash on startup with this output:
/usr/local/lib/plexhometheater/system/ImageLib-x86_64-freebsd.so: Undefined symbol "dll_fopen"

ImageLib is loaded as a shared library when it is required. The ImageLib code includes a few calls to functions in the main XBMC codebase. Shared libraries do not have access to the functions in the main program, unless the linker of the main program is called with --export-dynamic argument (which can be achieved by adding the -rdynamic argument to the compiler flags).

This can be achieved in CMAKE by adding ENABLE_EXPORTS. The reason this is a problem on FREEBSD and doesn't show in Linux, is CMake sets this property by default on Linux, but doesn't on FreeBSD. The comments in the CMake Linux code say it is there for historical reasons for projects which don't set ENABLE_EXPORTS. Therefore, this should be set on all builds.

For reference, here is an excerpt from the ld(1) manpage that explains this behaviour:
--export-dynamic
When creating a dynamically linked executable, add all symbols to
the dynamic symbol table. The dynamic symbol table is the set of
symbols which are visible from dynamic objects at run time.

If you do not use this option, the dynamic symbol table will
normally contain only those symbols which are referenced by some
dynamic object mentioned in the link.

If you use "dlopen" to load a dynamic object which needs to refer
back to the symbols defined by the program, rather than some other
dynamic object, then you will probably need to use this option when
linking the program itself.

You can also use the dynamic list to control what symbols should be
added to the dynamic symbol table if the output format supports it.
See the description of --dynamic-list.

This was discussed here:
https://forums.plex.tv/index.php/topic/123207-freebsd-pht-crashes-on-startup-with-error-undefined-symbol-dll-fopen/