Thread overview | |||||
---|---|---|---|---|---|
|
August 13, 2006 How to create shared library on linux? | ||||
---|---|---|---|---|
| ||||
I dont know how to create a shared library using dmd or build(http://dsource.org/projects/build). I try to compile the D source files to .o, and link them: # dmd -c *.d # gcc -o Test.so -shared *.o -lphobos I get som errors: ...ld: Test.so: undefined versioned symbol name _d_throw@4 ...ld: failed to set dynamic section sizes: Bad value collect2: ld returned 1 exit status Other questions: 1. How to link a shared library in dmd? I have a shared library, named libtest.so. In gcc, I can do this: # gcc -o test test.c -ltest In dmd, I don't know how to do that. 2. On linux, where do I place the gc code? Like DllMain, See "http://digitalmars.com/d/dll.html". |
August 14, 2006 Re: How to create shared library on linux? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Li Jie | Li Jie wrote: > I dont know how to create a shared library using dmd or build(http://dsource.org/projects/build). > > I try to compile the D source files to .o, and link them: > # dmd -c *.d > # gcc -o Test.so -shared *.o -lphobos > DMD can not create shared libraries on linux yet, but GDC can. > > Other questions: > 1. > How to link a shared library in dmd? I have a shared library, named libtest.so. > In gcc, I can do this: > # gcc -o test test.c -ltest > In dmd, I don't know how to do that. On linux, DMD uses GCC as its linker so you'd just do something like... dmd file.d -L-ltest If I remember correctly. Or dmd -c file.d gcc file.o -o file -ltest |
August 14, 2006 Re: How to create shared library on linux? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Li Jie | sön 2006-08-13 klockan 18:31 +0000 skrev Li Jie:
> I dont know how to create a shared library using dmd or build(http://dsource.org/projects/build).
>
> I try to compile the D source files to .o, and link them:
> # dmd -c *.d
> # gcc -o Test.so -shared *.o -lphobos
Try adding the -fPIC flag, like so:
gcc -o libTest.so -shared -fPIC *.o -lphobos
don't forget that libraries need to be named libMyLibName.so for the linker to find them. (Note the "lib" in the beginning of the file name)
/Anders
|
Copyright © 1999-2021 by the D Language Foundation