I'm very new to Yesod and I'm having trouble building Yesod statically
so I can deploy to Heroku.

I have changed the default .cabal file to reflect static compilation


if flag(production)
   cpp-options:   -DPRODUCTION
   ghc-options:   -Wall -threaded -O2 -static -optl-static

  
  else
         ghc-options:   -Wall -threaded -O0


And it no longer builds.  I get a whole bunch of warnings and then a
slew of undefined references like this:

Linking dist/build/personal-website/personal-website ...
/usr/lib/ghc-7.0.3/libHSrts_thr.a(Linker.thr_o): In function
`internal_dlopen':
Linker.c:(.text+0x407): warning: Using 'dlopen' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/ghc-7.0.3/unix-2.4.2.0/libHSunix-2.4.2.0.a(HsUnix.o): In
function `__hsunix_getpwent':
HsUnix.c:(.text+0xa1): warning: Using 'getpwent' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/ghc-7.0.3/unix-2.4.2.0/libHSunix-2.4.2.0.a(HsUnix.o): In
function `__hsunix_getpwnam_r':
HsUnix.c:(.text+0xb1): warning: Using 'getpwnam_r' in statically
linked applications requires at runtime the shared libraries from the
glibc version used for linking
/usr/lib/libpq.a(thread.o): In function `pqGetpwuid':
(.text+0x15): warning: Using 'getpwuid_r' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/libpq.a(ip.o): In function `pg_getaddrinfo_all':
(.text+0x31): warning: Using 'getaddrinfo' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/ghc-7.0.3/site-local/network-2.3.0.2/
libHSnetwork-2.3.0.2.a(BSD__63.o): In function `sD3z_info':
(.text+0xe4): warning: Using 'gethostbyname' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/ghc-7.0.3/site-local/network-2.3.0.2/
libHSnetwork-2.3.0.2.a(BSD__164.o): In function `sFKc_info':
(.text+0x12d): warning: Using 'getprotobyname' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/ghc-7.0.3/site-local/network-2.3.0.2/
libHSnetwork-2.3.0.2.a(BSD__155.o): In function `sFDs_info':
(.text+0x4c): warning: Using 'getservbyname' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/libpq.a(fe-misc.o): In function `pqSocketCheck':
(.text+0xa2d): undefined reference to `SSL_pending'
/usr/lib/libpq.a(fe-secure.o): In function `SSLerrmessage':
(.text+0x31): undefined reference to `ERR_get_error'
/usr/lib/libpq.a(fe-secure.o): In function `SSLerrmessage':
(.text+0x41): undefined reference to `ERR_reason_error_string'
/usr/lib/libpq.a(fe-secure.o): In function `initialize_SSL':
(.text+0x2f8): undefined reference to `SSL_check_private_key'
/usr/lib/libpq.a(fe-secure.o): In function `initialize_SSL':
(.text+0x3c0): undefined reference to `SSL_CTX_load_verify_locations'
(... snip ...)


If I just compile with just -static and without -optl-static
everything builds fine but the application crashes when it tries to
start on Heroku.

2011-12-28T01:20:51+00:00 heroku[web.1]: Starting process with command
`./dist/build/personal-website/personal-website -p 41083`
2011-12-28T01:20:51+00:00 app[web.1]: ./dist/build/personal-website/
personal-website: error while loading shared libraries: libgmp.so.10:
cannot open shared object file: No such file or directory
2011-12-28T01:20:52+00:00 heroku[web.1]: State changed from starting
to crashed


I tried adding libgmp.so.10 to the LD_LIBRARY_PATH as suggested in here
and then got the following error:

2011-12-28T01:31:23+00:00 app[web.1]: ./dist/build/personal-website/
personal-website: /lib/libc.so.6: version `GLIBC_2.14' not found
(required by ./dist/build/personal-website/personal-website)
2011-12-28T01:31:23+00:00 app[web.1]: ./dist/build/personal-website/
personal-website: /lib/libc.so.6: version `GLIBC_2.14' not found
(required by /app/dist/build/personal-website/libgmp.so.10)
2011-12-28T01:31:25+00:00 heroku[web.1]: State changed from starting
to crashed
2011-12-28T01:31:25+00:00 heroku[web.1]: Process exited


It seems that the version of libc that I'm compiling against is
different.  I tried also adding libc to the batch of libraries the
same way I did for libgmp but this results in a segmentation fault
when the application starts on the Heroku side.

Everything works fine on my PC.  I'm running 64bit archlinux with ghc
7.0.3.  The blog post on the official Yesod blog looked pretty easy
but I'm stumped at this point.  Anyone have any ideas?  If there's a way to get this thing working without building statically I'm open to that too.

EDIT

Per Employed Russians answer I did the following to fix this.

First created a new directory lib under the project directory and copied the missing shared libraries into it.  You can get this information by running ldd path/to/executable and heroku run ldd path/to/executable and comparing the output.

I then did heroku config:add LD_LIBRARY_PATH=./lib so when the application is started the dynamic linker will look for libraries in the new lib directory.

Finally I created an ubuntu 11.10 virtual machine and built and deployed to Heroku from there, this has an old enough glibc that it works on the Heroku host.

Edit:
I've since written a tutorial on the Yesod wiki


Question: Change of basis in non-linear Schrodinger equation
Answer: Here is my attempt at an answer, following the suggestion of @Lagerbaer. We first subtitute the Fourier Transform for $\psi_{LP}(k)$,

\begin{equation}
\psi_{LP}(k)=\int dxe^{-ikx}\psi_{LP}(x),
\end{equation}

and get

\begin{multline}
\int dxe^{-ikx}i\frac{d}{dt}\psi_{LP}(x)=\int dx\left[\epsilon(k)-i\frac{\gamma(k)}{2}\right]e^{-ikx}\psi_{LP}(x)\\+F_{p}(k)\,\, e^{-i\omega_{p}t}
+\int dx_{3}dx_{1}dx_{2}\\ \times \sum_{q_{1},q_{2}}g_{k,q_{1},q_{2}}\, e^{i(q_{1}+q_{2}-k)x_{3}}\psi_{LP}^{\star}(x_{3})\, e^{-iq_{1}x_{1}}\psi_{LP}(x_{1})\, e^{-iq_{2}x_{2}}\psi_{LP}(x_{2}).
\end{multline}

In order to simplify this expression, we need to apply the inverse transform to both sides (multiply by $\int dke^{ikx}$), obtaining

\begin{multline}
i\frac{d}{dt}\psi_{LP}(x)=\int dx^{\prime}\psi_{LP}(x^{\prime})\int dk\left[\epsilon(k)-i\frac{\gamma(k)}{2}\right]e^{ik(x-x^{\prime})}+F_{p}e^{i(k_{p}x-\omega_{p}t)}\\
+\int dke^{ikx}\int dx_{3}dx_{1}dx_{2}\\
\times\sum_{q_{1},q_{2}}g_{k,q_{1},q_{2}}\, e^{i(q_{1}+q_{2}-k)x_{3}}\psi_{LP}^{\star}(x_{3})\, e^{-iq_{1}x_{1}}\psi_{LP}(x_{1})\, e^{-iq_{2}x_{2}}\psi_{LP}(x_{2}).
\end{multline}

Now we look at an integral of the form $\int dx^{\prime}\psi_{LP}(x^{\prime})\int dkf(k)e^{ik(x-x^{\prime})}$, for a generic function $f(k)$. We expand our generic function in a Taylor Series around $k=0$, and get:

\begin{equation}
\sum_{n=0}^{\infty}\frac{f^{(n)}(0)}{n!}\int dx^{\prime}\psi_{LP}(x^{\prime})\int dkk^{n}e^{ik(x-x^{\prime})}=\sum_{n=0}^{\infty}\frac{f^{(n)}(0)}{n!}\left(-i\right)^{n}\int dx^{\prime}\psi_{LP}(x^{\prime})\partial_{x}^{n}\delta(x-x^{\prime})
\end{equation}

where we have used the well-known relation $\int dkk{}^{n}e^{ik(x-x^{\prime})}=\left(-i\right)^{n}\partial_{x}^{n}\delta(x-x^{\prime})$.

Moving the derivative operator to act on $\psi$ (integration by parts), we finally obtain

\begin{equation}
\int dx^{\prime}\psi_{LP}(x^{\prime})\int dkf(k)e^{ik(x-x^{\prime})}=\sum_{n=0}^{\infty}\frac{f^{(n)}(0)}{n!}(i\partial_{x})^{n}\psi_{LP}(x)=f(i\partial_{x})\psi_{LP}(x)
\end{equation}

Therefore, the first term on the RHS of our equation simplifies to $\left[\epsilon(i\partial_{x})-i\frac{\gamma(i\partial_{x})}{2}\right]\psi_{LP}(x)$ and we are left dealing with the interaction term.

\begin{equation}
\int dx_{3}\psi_{LP}^{\star}(x_{3})\int dx_{1}\psi_{LP}(x_{1})\int dq_{1}e^{iq_{1}(x_{3}-x_{1})}\int dx_{2}\psi_{LP}(x_{2})\int dq_{2}e^{iq_{2}(x_{3}-x_{2})}\int dkg(k,q_{1},q_{2})e^{ik(x-x_{3})}
\end{equation}

Substituting the form of $g(k,q_{1},q_{2})$, we get

\begin{equation}
g\int dx_{3}\psi_{LP}^{\star}(x_{3})\int dx_{1}\psi_{LP}(x_{1})\int dq_{1}X(q_{1})e^{iq_{1}(x_{3}-x_{1})}\int dx_{2}\psi_{LP}(x_{2})\int dq_{2}X(q_{2})e^{iq_{2}(x_{3}-x_{2})}\int dk\, X^{\star}(k)\, X^{\star}(q_{1}+q_{2}-k)\, e^{ik(x-x_{3})}
\end{equation}

And here is where I got stuck..