[英]Statically linking Haskell program using stack on Amazon Linux, to use on AWS Lambda
I'm trying to build a statically linked 'hello world' Haskell program on an EC2 instance, with a view to running it on AWS Lambda. 我正在尝试在EC2实例上构建一个静态链接的“hello world”Haskell程序,以便在AWS Lambda上运行它。
My only modification to the 'simple' stack.yaml is: 我对'simple'stack.yaml的唯一修改是:
ghc-options:
"*": -static -optc-static -optl-static -optl-pthread
I first got the following errors: 我首先遇到以下错误:
[ec2-user@ip-172-31-0-238 lambdatest]$ stack build
lambdatest-0.1.0.0: configure
Configuring lambdatest-0.1.0.0...
lambdatest-0.1.0.0: build
Preprocessing executable 'lambdatest' for lambdatest-0.1.0.0...
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/lambdatest/lambdatest ...
/usr/bin/ld: cannot find -lgmp
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lrt
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
The first thing I tried was to install gmp-devel: 我尝试的第一件事是安装gmp-devel:
[ec2-user@ip-172-31-0-238 lambdatest]$ sudo yum install gmp-devel.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
Package gmp-devel-6.0.0-11.16.amzn1.x86_64 already installed and latest version
Nothing to do
but it looks like that isn't the issue. 但看起来这不是问题。
Next I installed glibc-static and gmp-static, and now the error I see is: 接下来我安装了glibc-static和gmp-static,现在我看到的错误是:
[ec2-user@ip-172-31-0-238 lambdatest]$ stack build
lambdatest-0.1.0.0: build
Preprocessing executable 'lambdatest' for lambdatest-0.1.0.0...
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/lambdatest/lambdatest ...
/home/ec2-user/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/rts/libHSrts.a(Linker.o): In function `internal_dlopen':
Could not resolve file /home/ben/ghc-7.10.2/rts/Linker.c
But when I run the identical 'stack build' command a second time, it completes without error. 但是当我第二次运行相同的“堆栈构建”命令时,它完成没有错误。
So what worked for me was: 那么对我有用的是:
Add the fpcomplete repo: 添加fpcomplete repo:
curl -sSL https://s3.amazonaws.com/download.fpcomplete.com/centos/7/fpco.repo | \
sudo tee /etc/yum.repos.d/fpco.repo
Install stack: 安装堆栈:
sudo yum -y install stack
Install ghc: 安装ghc:
stack setup
Create a new stack project: 创建一个新的堆栈项目:
stack new lambdatest simple
Modify stack.yaml with the following flags: 使用以下标志修改stack.yaml:
ghc-options:
"*": -static -optc-static -optl-static -optl-pthread
Install static versions of libraries: 安装库的静态版本:
sudo yum install glibc-static
sudo yum install gmp-static
Then run stack build
twice ! 然后运行stack build
两次 !
The resulting executable runs OK on my EC2 instance and also runs on AWS Lambda when started by a Node.js launcher function. 生成的可执行文件在我的EC2实例上运行正常,并且在由Node.js启动程序函数启动时也在AWS Lambda上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.