$ ./dmd hello.d
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/bin/ld: hello.o: relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
hello.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
--- errorlevel 1
$ ./dmd -fPIC hello.d
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/bin/ld: ./../lib64/libphobos2.a(object__c_58c.o): relocation R_X86_64_32 against `_D10TypeInfo_m6__initZ' can not be used when making a shared object; recompile with -fPIC
./../lib64/libphobos2.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
--- errorlevel 1
Comment #1 by maxim — 2012-08-15T07:57:01Z
Which version of dmd are you using and what is in hello.d?
It seems dmd is incompatible with Gentoo Hardened gcc.
Comment #4 by wbrana — 2012-08-15T08:45:11Z
following command fails also with non-hardened gcc
./dmd -shared -fPIC hello.d
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2-pre9999/../../../../x86_64-pc-linux-gnu/bin/ld: ./../lib64/libphobos2.a(object__c_58c.o): relocation R_X86_64_32 against `_D10TypeInfo_m6__initZ' can not be used when making a shared object; recompile with -fPIC
./../lib64/libphobos2.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
--- errorlevel 1
Comment #5 by maxim — 2012-08-15T10:28:14Z
(In reply to comment #4)
> following command fails also with non-hardened gcc
>
> ./dmd -shared -fPIC hello.d
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2-pre9999/../../../../x86_64-pc-linux-gnu/bin/ld:
> ./../lib64/libphobos2.a(object__c_58c.o): relocation R_X86_64_32 against
> `_D10TypeInfo_m6__initZ' can not be used when making a shared object; recompile
> with -fPIC
> ./../lib64/libphobos2.a: could not read symbols: Bad value
> collect2: error: ld returned 1 exit status
> --- errorlevel 1
Libraries may be built in two steps
(currently I don't know better solution):
dmd hello.d -fPIC -c
gcc --shared hello.o -o ...
if there is really need to make a library with main function.
Additionally, when linking object files from manually compiled sources,
core modules have to be linked with phobos2.a, librt.so, libpthread.so.
Comment #6 by ibuclaw — 2015-02-13T10:10:18Z
*** Issue 14175 has been marked as a duplicate of this issue. ***
Comment #7 by code — 2015-03-29T22:52:24Z
Try using this to build a shared library.
dmd -shared -fPIC hello.d --defaultlib=libphobos2.so
Comment #8 by robert.schadek — 2024-12-13T18:01:01Z