DMD Fails with fPIC error
Reuben via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 22 03:44:03 PDT 2014
Thanks, that did the trick.
Here's a summary post for anyone else with the same problem:
Problem:
DMD uses GCC to perform linking. On Hardened Gentoo (and
derivatives like Sabayon), GCC implies -fPIE, which causes
linking to fail if phobos and druntime were not compiled with
-fPIC. You can check if this is the case by looking at the output
of `gcc --version` - it will include the phrase Gentoo Hardened.
Workaround A:
Dynamically link Phobos instead.
$ dmd -defaultlib=:libphobos2.so -fPIC test.d
Workaround B:
Use a non-hardened compiler, such as Clang or a vanilla build of
GCC. (Compiling GCC takes about 7 GB and 40 min, which makes it
more expensive than actually fixing the problem).
$ env CC=/usr/bin/clang dmd test.d
Actual Fix:
Compile Phobos and Druntime with PIC=1. Note that for ebuilds,
this includes the install target (which presumably does some
linking).
You can then compile programs with:
$ dmd -fPIC test.d
Additional Notes:
-I've submitted a pull request to the overlay so that PIC is set
automatically if hardened GCC is detected.
-LDC currently has the same problem. I'll probably look at fixing
it in the near future.
More information about the Digitalmars-d-learn
mailing list