--ld_preload

This flag is named after the environment variable LD_PRELOAD used by ld-linix. Like LD_PRELOAD its value is a space-separated list of shared libraries to be preloaded and packaged with the application.

Note

This flag ONLY affects the packaging process, not running the Ermine-packaged executable.

But if --ld-preload doesn't affect running the Ermine-packed executable, then why bothering specifying it at all?

By default Ermine will only package the executable itself and all shared libraries reported by the ldd command. While this is a good start, ldd is unable to detect libraries that are dynamically loadded by an application via dlopen. So --ld_preload is a way to tell Ermine that certain libraries need to be packaged too.

Why use the --ld-preload option instead of just specifying those libraries in the config file? There are two reasons:

  • ErmineLight doesn't offer the --config option.
  • ErminePro has the --config option. While it's possible to use a config file instead of the --ld_preload option, it is usually inconvenient to do so: often one shared library needs another one, and then in turn they may need more, so tracking all of them can be time-consuming and error-prone.

Example 2.1.  Adding libQtCore.so.4 to a packaged application using --config

First let's see what shared libraries libQtCore.so.4 depends on:
$ /usr/lib/libQtCore.so.4
	linux-gate.so.1 =>  (0x006c5000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00f5a000)
	libz.so.1 => /lib/libz.so.1 (0x00b57000)
	libdl.so.2 => /lib/libdl.so.2 (0x00f39000)
	libgthread-2.0.so.0 => /lib/libgthread-2.0.so.0 (0x00f0c000)
	librt.so.1 => /lib/librt.so.1 (0x0068d000)
	libglib-2.0.so.0 => /lib/libglib-2.0.so.0 (0x00d9c000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00110000)
	libm.so.6 => /lib/libm.so.6 (0x006ec000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x009a3000)
	libc.so.6 => /lib/libc.so.6 (0x00716000)
	/lib/ld-linux.so.2 (0x005a6000)
Next, a config file should be created:
# config.txt
/lib/libpthread.so.0     internal
/lib/libz.so.1           internal
/lib/libdl.so.2          internal
/lib/libgthread-2.0.so.0 internal
/lib/librt.so.1          internal
/lib/libglib-2.0.so.0    internal
/usr/lib/libstdc++.so.6  internal
/lib/libm.so.6           internal
/lib/libgcc_s.so.1       internal
/lib/libc.so.6           internal
/lib/ld-linux.so.2       internal
And finally Ermine should be invoked:
$ ErminePro --config=config.txt ...

Here's another way to achieve the same:

Example 2.2.  Adding libQtCore.so.4 to a packaged application using --ld-preload

$ ErminePro --ld_preload=libQtCore.so.4 ...
That's it!

Personally I prefer the latter way, but of course you might find one that suits you better.