When using the following in my stack.yaml
to (attempt) to compile a static binary through Stack:
ghc-options:
"*": -static -optc-static -optl-static -optl-pthread -fPIC
I get this error:
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)
I'm using stack with docker enabled and a customised Amazon Linux image for building a static binary for use with AWS Lambda.
I have no prior experience with static binary compilation, so I'm a bit stumped on this linker error. Any ideas please?
Here's the gcc args using -v:
/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