当前位置: 首页 > 面试题库 >

将Yesod部署到Heroku,无法静态构建

彭鹭洋
2023-03-14
问题内容

我是Yesod的新手,无法静态构建Yesod,因此可以部署到Heroku。

我已更改默认的.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 ...)

如果我仅使用just进行编译,-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,它具有足够老的glibc,可以在Heroku主机上运行。

编辑:从那以后我就在Yesod Wiki上写了一个教程


问题答案:

我不知道Yesod是什么,但我 确切 知道您其他每个错误的含义。

首先,你应该 尝试静态链接。您得到的警告是完全正确的: 如果 您静态链接并使用要获得警告的例程之一,则必须安排在与libc.so.6版本
完全相同 的系统上运行您在构建时使用过。

与普遍的看法相反,静态链接在Linux上生成的是 更少 但不是更多的可移植可执行文件。

您的其他(静态)链接错误是由于libopenssl.a链接时丢失而引起的。

但是,让我们假设您将走“明智的”路线,并使用动态链接。

对于动态链接,Linux(和大多数其他UNIX)支持向后兼容:旧的二进制文件继续在较新的系统上运行。但是它们不支持前向兼容性(在较新的系统上构建的二进制文件通常
不会 在较旧的系统上运行)。

但这就是您要尝试的:您在具有glibc-2.14(或更高版本)的系统上构建,并且在具有glibc-2.13(或更高版本)的系统上运行。

你需要知道的另一件事是,glibc的是由一些200+二进制文件必须全部匹配的 准确 。两个关键的二进制文件/lib/ld- linux.so/lib/libc.so.6(但还有更多:libpthread.so.0libnsl.so.1,等等)。如果其中一些二进制文件来自不同版本的glibc,则通常会崩溃。这就是您尝试将glibc-2.14
libc.so.6放在LD_LIBRARY_PATH-它不再与系统匹配时所得到的/lib/ld-linux

那么有什么解决方案呢?有几种可能性(难度越来越大):

  1. 您可以将ld-2.14.so/lib/ld-linux符号链接的目标)复制到目标系统,并显式调用它:
    /path/to/ld-2.14.so --library-path <whatever> /path/to/your/executable
    

这通常可以正常工作,但会混淆看着的应用程序argv[0],并中断那些自己重新执行的应用程序。

  1. 您可以在较旧的系统上构建。

  2. 你可以使用appgcc(这个选项已经消失了,看到这为它曾经被描述)。

  3. 您可以设置与目标系统匹配的chroot环境,并在该chroot中进行构建。

  4. 您可以构建自己的Linux到旧版Linux交叉编译器



 类似资料:
  • 问题内容: 香港专业教育学院一直试图与heroku合作。我可以成功地使其在开发模式下工作,但是当我尝试推送到heroku时,我得到了 然后,我阅读并关注了http://blog.redistogo.com/2010/07/26/resque-with-redis-to- go/ 我把站点中列出的配置放了,但是出现了以下错误 我把我的初始化器/ resque.rb 但是它引发了上面提到的错误。在我的

  • 问题内容: 因此,我正在遵循来自Heroku和Django的入门指南。但是,当我运行此命令时: 我得到这个错误 我以为这意味着尚未设置数据库…所以我也手动添加了shared_db选项: 但是..我仍然收到相同的错误。是什么赋予了? 问题答案: 我的应用程序结构已关闭… heroku希望结构看起来像这样:

  • 我正在尝试部署谷歌云SQL Server作为我的数据库。我目前在本地使用谷歌云SQL代理。但很明显,要部署到heroku,我无法做到这一点。 下面有人说他们有解决这个问题的方法。https://elements.heroku.com/buildpacks/emartech/heroku-buildpack-cloud-sql-proxy#buildpack-instructions 我能够运行他们

  • 我正在尝试在Heroku上部署一个可执行的Spring Bootjar。 我已经告诉Heroku从只包含以下文件的github存储库进行部署: 我的如下所示: 如果我查看github中的构建包项目,我可以看到有一个名为的脚本,它检查是否存在文件: https://github.com/heroku/heroku-buildpack-java/blob/master/bin/detect 我相信我的

  • 当我试图在heroku上部署springboot应用程序时,出现了以下错误: 无法执行目标org.apache.Maven.plugins:maven-compiler-plugin:3.8.1:在项目后端编译(default-compile):错误编译:无效的目标版本:11->[Help 1]Remote:[error]Remote:[error]要查看错误的全部堆栈跟踪,请使用-e开关重新运行

  • 问题内容: 我正在使用Heroku部署NodeJs应用程序。除了提供静态文件的一个小问题外,其他所有东西都工作正常。 我有以下配置 除非我尝试提供子文件夹中的静态文件,否​​则它工作正常。 www.example.com/bar.js //这会提供文件/htdocs/bar.js www.example.com/foo/bar.js //无法找到文件/htdocs/foo/bar.js 我忘了说在