strange -fPIC compilation error
Lodovico Giaretta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Oct 30 17:14:22 PDT 2016
On Monday, 31 October 2016 at 00:08:59 UTC, Charles Hixson wrote:
> So now I removed the repository version of dmd and dub,
> downloaded DMD64 D Compiler v2.072.0-b2, used dkpg to install
> it, and appear to get the same errors.
>
> (Well, actually I removed the commenting out of the code, but
> it compiles and runs properly with ldc2.)
I don't think it's a problem of DMD. This is due to your gcc
installation being hardened, that is, configured to produce PIE
by default. To produce PIE, the linker needs to be fed PIC, which
DMD does not produce by default. The -fPIC flags makes DMD
produce PIC out of your sources. The problem is, libphobos2.a
(the static version of Phobos) is not compiled with -fPIC, so
even if your code is PIC, gcc will complain. The workaround is to
use -defaultlib=libphobos2.so to dynamically link with the shared
version of Phobos. Being it a shared object, it does not give any
problem with PIE.
Looking on internet, I didn't find any clue about Debian shipping
an hardened gcc, but this is the only cause I can think of for
the behaviour you are experiencing.
More information about the Digitalmars-d-learn
mailing list