我正在尝试在 EC2 实例上构建一个静态链接的“hello world”Haskell 程序,以便在 AWS Lambda 上运行它。
我对“简单”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
但是,当我第二次运行相同的“堆栈构建”命令时,它会毫无错误地完成。