使用 Amazon Linux 上的堆栈静态链接 Haskell 程序,以便在 AWS Lambda 上使用
Statically linking Haskell program using stack on Amazon Linux, to use on AWS Lambda
我正在尝试在 EC2 实例上构建一个静态链接的 'hello world' Haskell 程序,以期 运行 在 AWS Lambda 上运行它。
我对 'simple' stack.yaml 的唯一修改是:
ghc-options:
"*": -static -optc-static -optl-static -optl-pthread
我首先得到以下错误:
[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
我尝试的第一件事是安装 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
但看起来这不是问题所在。
接下来我安装了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
但是当我第二次 运行 相同的 'stack build' 命令时,它没有错误地完成。
所以对我有用的是:
添加 fpcomplete 存储库:
curl -sSL https://s3.amazonaws.com/download.fpcomplete.com/centos/7/fpco.repo | \
sudo tee /etc/yum.repos.d/fpco.repo
安装堆栈:
sudo yum -y install stack
安装 ghc:
stack setup
新建堆栈项目:
stack new lambdatest simple
使用以下标志修改 stack.yaml:
ghc-options:
"*": -static -optc-static -optl-static -optl-pthread
安装库的静态版本:
sudo yum install glibc-static
sudo yum install gmp-static
然后运行stack build
两次!
生成的可执行文件 运行 在我的 EC2 实例上正常,并且在由 Node.js 启动器函数启动时在 AWS Lambda 上 运行s 正常。
我正在尝试在 EC2 实例上构建一个静态链接的 'hello world' Haskell 程序,以期 运行 在 AWS Lambda 上运行它。
我对 'simple' stack.yaml 的唯一修改是:
ghc-options:
"*": -static -optc-static -optl-static -optl-pthread
我首先得到以下错误:
[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
我尝试的第一件事是安装 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
但看起来这不是问题所在。
接下来我安装了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
但是当我第二次 运行 相同的 'stack build' 命令时,它没有错误地完成。
所以对我有用的是:
添加 fpcomplete 存储库:
curl -sSL https://s3.amazonaws.com/download.fpcomplete.com/centos/7/fpco.repo | \
sudo tee /etc/yum.repos.d/fpco.repo
安装堆栈:
sudo yum -y install stack
安装 ghc:
stack setup
新建堆栈项目:
stack new lambdatest simple
使用以下标志修改 stack.yaml:
ghc-options:
"*": -static -optc-static -optl-static -optl-pthread
安装库的静态版本:
sudo yum install glibc-static
sudo yum install gmp-static
然后运行stack build
两次!
生成的可执行文件 运行 在我的 EC2 实例上正常,并且在由 Node.js 启动器函数启动时在 AWS Lambda 上 运行s 正常。