[Ur] about the -static compiler flag

Chris Double chris.double at double.co.nz
Fri Nov 23 05:04:25 EST 2018


On Wed, Oct 31, 2018 at 8:28 AM Adam Chlipala <adamc at csail.mit.edu> wrote:
>
> I don't know if this GitHub issue is related, but in general I made a token effort (about 10 years ago) to support static linking by adding one flag to the GCC/Clang command line, and it has been clear for years that more modifications are needed somehow.  I don't intend to research them myself since I literally always use dynamic linking for Ur/Web apps, but I would be very glad to see related PRs.

It's possible to get a complete static executable from urweb by using
musl-libc [1] and a workaround. I tried with a simple "hello world"
type project, with musl installed:

$ urweb -protocol http -output test -ccompiler musl-gcc -static hello1
/usr/bin/ld: /usr/local/lib/liburweb.a(urweb.o): in function
`uw_Basis_fromDatetime':
urweb/src/c/urweb.c:4241: undefined reference to `timelocal'
collect2: error: ld returned 1 exit status

Unfortunately musl doesn't support 'timelocal'. I created a stub for
this by a definition in a 'time.c', compiling it with musl-gcc, and
adding a "link time.o" in my urweb project. This worked, and I got a
static executable that run and served the example project.

As well as the 'timelocal' stub, I had to compile openssl and libz as
static libraries installed in /usr/local/musl' to link to them
statically.

Would you be interested in a PR for replacing timelocal usage?

[1] https://www.musl-libc.org/

-- 
http://bluishcoder.co.nz



More information about the Ur mailing list