www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - DUB not passing "dflags": ["-fPIC"] for gdc, ldmd2 only for DMD

I'm coming from this thread: 
http://forum.dlang.org/thread/zzjeajhjpzhnvgxquluu forum.dlang.org

I a nutshell:

- DUB didn't compile my dynamic library project, and Martin 
linked me this issue: 
https://github.com/D-Programming-Language/dub/issues/352. The 
workaround is to put: "dflags": ["-fPIC"] in dub.json
- It builds and works if dub uses DMD. But if I invoke it with 
--complier=gdc, or --compiler=ldmd2, then the linker issue arise 
again, DUB not emit -fPIC I think.

dub.json:

{
	"name": "node-d-sample",
	"description": "A minimal D application.",
	"copyright": "Copyright © 2014, gabor",
	"authors": ["gabor"],
	"dependencies": {
	},
	"libs": [ "phobos2" ],
	"targetName": "node-d-sample",
	"targetPath": "lib",
	"targetType": "dynamicLibrary",
         "dflags": ["-fPIC"]
}

dub --compiler=gdc:

Performing main compilation...
dub build "node-d-sample" --arch=x86_64 --compiler=gdc
"--build=release"
Building package node-d-sample in
/home/gabor/sandbox/node-d-sample/
Building node-d-sample ~master configuration "library", build
type release.
Running gdc...
/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgphobos2.a(minfo.o):
relocation R_X86_64_32 against
`_D32TypeInfo_APxS6object10ModuleInfo6__initZ' can not be used
when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgphobos2.a: error adding
symbols: Bad value
collect2: error: ld returned 1 exit status
FAIL
.dub/build/library-release-linux.posix-x86_64-gdc_2065-33A38D9D3DC714C1501A18C957A2B35B/
node-d-sample dynamicLibrary
Error executing command build: gdc failed with exit code 1.

Exit code 2
Build complete -- 1 error, 0 warnings

dub --compiler=ldmd2:

Performing main compilation...
dub build "node-d-sample" --arch=x86_64 --compiler=ldmd2
"--build=release"
The determined compiler type "ldc" doesn't match the expected
type "dmd". This will probably result in build errors.
Building package node-d-sample in
/home/gabor/sandbox/node-d-sample/
Building node-d-sample ~master configuration "library", build
type release.
Running ldmd2...
/usr/bin/ld:
/home/gabor/dev/ldc2-0.15.0-beta1-linux-x86_64/bin/../lib/libdruntime-ldc.a(eh.o):
relocation R_X86_64_32 against `.rodata..str1' can not be used
when making a shared object; recompile with -fPIC
/home/gabor/dev/ldc2-0.15.0-beta1-linux-x86_64/bin/../lib/libdruntime-ldc.a:
error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
FAIL
.dub/build/library-release-linux.posix-x86_64-ldc_2066-212B345732639D80C27025028ED586A2/
node-d-sample dynamicLibrary
Error executing command build: ldmd2 failed with exit code 1.

Exit code 2
Build complete -- 1 error, 0 warnings
Dec 14 2014