DMD Fails with fPIC error

Reuben via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 14 05:01:06 PDT 2014


On Saturday, 14 June 2014 at 10:45:25 UTC, Mike Wey wrote:
> On 06/14/2014 03:58 AM, Reuben wrote:
>> Hi,
>> I'm new to D and am trying to compile a simple hello world 
>> program.
>> I get the following error when compiling it:
>>
>>> dmd test.d
>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld:
>> /opt/dmd-2.065/lib64/libphobos2.a(lifetime_488_4cd.o): 
>> relocation
>> R_X86_64_32 against `_D15TypeInfo_Shared7__ClassZ' can not be 
>> used when
>> making a shared object; recompile with -fPIC
>> /opt/dmd-2.065/lib64/libphobos2.a: could not read symbols: Bad 
>> value
>> collect2: error: ld returned 1 exit status
>> --- errorlevel 1
>>
>> This error occurs regardless of whether I use the -fPIC option 
>> or not.
>> Compiling DMD from source does not change anything.
>>
>> I am using DMD 2.065.0 on Sabayon amd64, compiled from the 
>> dlang overlay
>> with gcc (Gentoo Hardened 4.7.3-r1 p1.4, pie-0.5.5) 4.7.3.
>>
>> Thanks in advance.
>
> From the error it looks like you are compiling test.d as shared 
> while linking against the static version of the standard 
> library.
>
> If "dmd test.d" is the command being run there probably is an 
> error in with the configuration in dmd.conf, the conf file is 
> probably in /etc.
>
> Depending on the desired behavior you'll need to remove the 
> -shared flag from the configuration or add 
> -defaultlib=:libphobos2.so

dmd.conf contains the default settings. I haven't specified 
-shared anywhere. The only thing I can think of is that if -fPIC 
is required, DMD might be implying it somehow.

Compiling with -defaultlib seems to have fixed it. I'm getting a 
warning, but the program compiles and seems to run OK.

>dmd -defaultlib=:libphobos2.so -fPIC test.d
>/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: 
>test.o: warning: relocation in readonly section `.rodata'.
>/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: 
>warning: creating a DT_TEXTREL in object.

Is the warning something I should be worried about?


More information about the Digitalmars-d-learn mailing list