Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bundle GraphicsMagick with application?

I would like to bundle a standalone version of the GraphicsMagick gm binary with an application, so that I don't have to build and install the GraphicsMagick library on the server where the application is supposed to run.

Details

I'm creating a build system that can generate a tar-ball containing an entire node.js application including all the binary dependencies (in our case the node binary and the GraphicsMagick library). It then uploads it to a server, extracts it and run it.

I've tried to just ship it with a pre-compiled gm binary, but as expected gm depends on several libraries, so I get errors like gm: error while loading shared libraries: libGraphicsMagick.so.3: cannot open shared object file: No such file or directory.

I'm running OSX locally and our servers run Ubuntu.

like image 893
Thomas Watson Avatar asked Mar 26 '13 14:03

Thomas Watson


1 Answers

A solution is to build GraphicsMagick from source code and configure with the options --disable-shared --disable-installed. This will produce a static relocatable executable which only depends on shared libraries already on the system. Install into a temporary directory for packaging via something like 'make DESTDIR=/tmp/gminstalldir install'. You would also want to evaluate which libraries are available as standard on the target OS (so they can be depended on) and either add configure options to disable the ones which are not assured to be available, or link with a static version of the library so it is included in the 'gm' binary.

Another solution is to take the stock 'gm' binaries and create a shell script wrapper which sets certain environment variables (e.g. LD_LIBRARY_PATH) so that it can still run. This approach would add some run-time overhead and require some trial/error to get it working properly.

like image 168
Bob Friesenhahn Avatar answered Oct 27 '22 17:10

Bob Friesenhahn