当我在
stack.yaml
中使用以下内容来尝试通过Stack编译静态二进制文件时:ghc-options:
"*": -static -optc-static -optl-static -optl-pthread -fPIC
我遇到了这个错误:
usr/bin/ld: /usr/lib/gcc/x86_64-amazon-linux/4.8.3/crtbeginT.o: relocation R_X86_64_32 against `__TMC_END__' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-amazon-linux/4.8.3/crtbeginT.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
我正在使用启用了docker的stack,并使用定制的Amazon Linux镜像构建静态二进制文件以用于AWS Lambda。
我之前没有静态二进制编译的经验,所以对这个链接错误感到有些困惑。请问有什么建议吗?
以下是使用-v选项的gcc参数:
/usr/bin/gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE '-Wl,--hash-size=31' -Wl,--reduce-memory-overheads -Wl,--no-as-needed -Wl,-rpath<snipped LOADS> -lHSghc<SNIPPED LOADS> -lpq -lz -lrt -lutil -ldl -lgmp
gcc
调用,那将非常有帮助。也许在ghc-options
行中添加-v
可以解决问题。 - Reid Barton-o
标志。 - Reid Barton