Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building a dynamicLibrary result in linker error #352

Closed
Geod24 opened this issue Jun 19, 2014 · 2 comments
Closed

Building a dynamicLibrary result in linker error #352

Geod24 opened this issue Jun 19, 2014 · 2 comments
Milestone

Comments

@Geod24
Copy link
Member

Geod24 commented Jun 19, 2014

You're probably already aware of it, but search didn't prompt anything so I'm opening a new issue.

Simple use case: dub init testlib
Go into teslib, edit dub.json to add "targetType": "dynamicLibrary" and change app.d main() to test().

Then run dub, and:

geod@Barsoom:~/testlib$ \dub build --compiler=gdc-4.9 --force
testlib: ["testlib"]
Building testlib configuration "library", build type debug.
Running gdc-4.9...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.9/libgphobos2.a(object_.o): relocation R_X86_64_32S against `_D10TypeInfo_m6__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-debug-linux.posix-x86_64-gdc-4.9-EDE7316C4CF9D54D3D6146C2770BD5A3 testlib dynamicLibrary
Error executing command build: GDC compile run failed with exit code 1

geod@Barsoom:~/testlib$ \dub build --force
testlib: ["testlib"]
Building testlib configuration "library", build type debug.
Compiling...
Linking...
/usr/bin/ld: .dub/build/library-debug-linux.posix-x86_64-dmd-F0AFF9EF6E22D753597E009158EE6446/testlib.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
.dub/build/library-debug-linux.posix-x86_64-dmd-F0AFF9EF6E22D753597E009158EE6446/testlib.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
--- errorlevel 1
FAIL .dub/build/library-debug-linux.posix-x86_64-dmd-F0AFF9EF6E22D753597E009158EE6446 testlib dynamicLibrary
Error executing command build: Link command failed with exit code 1

Note that this is not a dub bug IMO. To work around this issue, one can use:
dmd app.d -fPIC -shared -oftest.so -defaultlib=libphobos2.so
OR
gdc app.d -fPIC -shared -o test.so -nodefaultlibs -lphobos2

@dnadlinger
Copy link
Member

Does GDC even support dynamic libraries yet?

@AntonMeep
Copy link
Member

Works with DMD and LDC, not sure about GDC but I assume it does too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants