asm*_*asm 27 linux haskell heroku static-linking yesod
我是Yesod的新手,我无法静态构建Yesod,因此我可以部署到Heroku.
我更改了默认的.cabal文件以反映静态编译
if flag(production)
cpp-options: -DPRODUCTION
ghc-options: -Wall -threaded -O2 -static -optl-static
else
ghc-options: -Wall -threaded -O0
Run Code Online (Sandbox Code Playgroud)
它不再构建.我得到了一大堆警告,然后是一大堆未定义的引用,如下所示:
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 ...)
Run Code Online (Sandbox Code Playgroud)
如果我只使用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
Run Code Online (Sandbox Code Playgroud)
我尝试将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
Run Code Online (Sandbox Code Playgroud)
似乎我正在编译的libc版本是不同的.我尝试将libc添加到批处理库中的方式与libgmp相同,但是当应用程序在Heroku端启动时会导致分段错误.
在我的电脑上一切正常.我用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上编写了一个教程
Emp*_*ian 55
我不知道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.0
,libnsl.so.1
等等).如果其中一些二进制文件来自不同版本的glibc,你通常会崩溃.这正是你得到的,当你试图将你的glibc-2.14 libc.so.6
放在LD_LIBRARY_PATH
- 它不再匹配系统时/lib/ld-linux
.
那么解决方案是什么?有几种可能性(增加难度):
您可以将ld-2.14.so
(/lib/ld-linux
符号链接的目标)复制到目标系统,并显式调用它:
/path/to/ld-2.14.so --library-path <whatever> /path/to/your/executable
Run Code Online (Sandbox Code Playgroud)
这通常有效,但可能会混淆查看的应用程序argv[0]
,并会破坏重新执行的应用程序.
您可以在旧系统上构建.
您可以使用appgcc
(此选项已消失,请参阅此说明以了解它曾经是什么).
您可以设置与目标系统匹配的chroot环境,并在该chroot内部构建.
您可以自己构建一个Linux-to-oldLinux交叉编译器
你有几个问题.
您不应该在前沿分布上构建生产二进制文件.生产系统上的库不能向前兼容.
您不应该静态链接glibc - 它将始终在运行时尝试加载其他库.例如基于cpu的程序集.这就是你的第一个警告.
最后一个链接器错误看起来与命令行上缺少的openssl库有关.
但总而言之 - 降级您的发行版.
归档时间: |
|
查看次数: |
29944 次 |
最近记录: |