私は Yesod を初めて使用し、Heroku にデプロイできるように Yesod を静的にビルドするのに苦労しています。
静的コンパイルを反映するようにデフォルトの .cabal ファイルを変更しました
if flag(production)
cpp-options: -DPRODUCTION
ghc-options: -Wall -threaded -O2 -static -optl-static
else
ghc-options: -Wall -threaded -O0
そして、それはもはや構築されません。大量の警告が表示された後、次のような未定義の参照が多数表示されます。
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 ...)
コンパイルするだけ-static
で-optl-static
すべてが正常にビルドされますが、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
ここで提案されているように、libgmp.so.10 を LD_LIBRARY_PATH に追加しようとした ところ、次のエラーが発生しました。
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
コンパイルしているlibcのバージョンが違うようです。libgmp の場合と同じ方法でライブラリのバッチに libc を追加しようとしましたが、Heroku 側でアプリケーションを起動するとセグメンテーション エラーが発生します。
私のPCではすべて正常に動作します。私はghc 7.0.3で64ビットのarchlinuxを実行しています。 公式の Yesod ブログのブログ投稿はかなり簡単に見えましたが、この時点で困惑しています。誰にもアイデアはありますか?静的にビルドせずにこのことを機能させる方法があれば、私もそれを受け入れます。
編集
回答ごとEmployed Russians
に、これを修正するために次のことを行いました。
まず、プロジェクト ディレクトリの下に新しいディレクトリを作成lib
し、不足している共有ライブラリをそこにコピーしました。この情報は、実行して出力を比較することで取得できldd path/to/executable
ますheroku run ldd path/to/executable
。
次にheroku config:add LD_LIBRARY_PATH=./lib
、アプリケーションが開始されると、ダイナミック リンカは新しい lib ディレクトリでライブラリを探します。
最後に、ubuntu 11.10 仮想マシンを作成し、そこからビルドして Heroku にデプロイしました。これには、Heroku ホストで動作する十分に古い glibc があります。
編集: 私はそれ以来、Yesod wikiでチュートリアルを書いています。