pcb-rnd knowledge pool


Static linking pcb-rnd

staticlink by Tibor 'Igor2' Palinkas on 2019-09-21

Tags: howto, static, link, compile, server, cli, batch, automated

node source



Abstract: In some special application a static linked version of pcb-rnd is required. The most typical static applications are rendering previews on a web server or converting data running pcb-rnd on a server as a service.

  Download this shell script and copy it to trunk/src then run it from src as ./static. It will configure and compile a static version of the pcb-rnd executable with the limitations listed below.


It is between hard and impossible to static link software that use X. gtk and glib don't make static linking easy either. Fortunately for the typical server-side application only the batch HID is needed so GUI is disabled in the configure step.

No external fungw

Most scripting languages are unsafe to run on server side because they let users access the file system or even execute shell scripts and programs. One of the advantages of libfawk is that it does not implement any such feature, which makes scripts "sandboxed" and safe to execute on server side. With only libfawk there are 3 embedded scripting languages available, which should be enough for most applications.

Limiting pcb-rnd to libfawk-only is done by ensuring system-installed fungw is not found, which gets configure to fall back to the limited version shipped with pcb-rnd. This is done by the "--prefix/libs/script/fungw=/dev/null" line that tells configure to look in /dev/null for the system installed fungw.

Disable wget and vfs

For security reasons it's best not to do any network traffic so fp_wget is disabled. The vfs plugins are disabled too to further reduce use of APIs that go beyond normal file system read/write.

Watch out for software upgrades: by the time of writing these were the plugins that could access foreign hosts and exotic APIs. But pcb-rnd is in constant development, there will be new plugins all the time, some may introduce networking or file system access. Before configuring pcb-rnd for server side use, always check what plugins are included and what risk each of those plugins means.

Manual injection of -static and -l flags in LDFLAGS

The build system is not prepared for testing libs for static linking. Some libs, like libxml2 (required e.g. for io_eagle), are not really designed for static linking. The sed line in the script fixes up the generated LDFLAGS for static linking with libxml2 and libgd.

Compile pcb-rnd only

Some versions of pcb-rnd will attempt to compile libs (e.g. the hidlib) and utils (e.g. gsch2pcb-rnd). Since we are interested only in a static linked pcb-rnd executable, the script calls make with an explicit target.