digitalmars.D.learn - How to create shared library on linux?
- Li Jie (16/16) Aug 13 2006 I dont know how to create a shared library using dmd or build(http://dso...
- clayasaurus (7/20) Aug 13 2006 On linux, DMD uses GCC as its linker so you'd just do something like...
- Li Jie (2/7) Aug 13 2006 Thanks, it is right.
- Anders Runesson (7/12) Aug 14 2006 Try adding the -fPIC flag, like so:
- Li Jie (30/31) Aug 15 2006 Thanks.
- Li Jie (2/4) Aug 15 2006 I try to write a ruby extension.
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: 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: 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".
Aug 13 2006
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 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: 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
Aug 13 2006
On linux, DMD uses GCC as its linker so you'd just do something like...dmd file.d -L-ltestIf I remember correctly. Ordmd -c file.d gcc file.o -o file -ltestThanks, it is right. I will try gdc to create shared library.
Aug 13 2006
s=C3=B6n 2006-08-13 klockan 18:31 +0000 skrev Li Jie:I dont know how to create a shared library using dmd or build(http://dsou=rce.org/projects/build).=20 I try to compile the D source files to .o, and link them: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
Aug 14 2006
DMD can not create shared libraries on linux yet, but GDC can.Thanks. I try to use gdc, but I get some errors. /*** CODE ***/ test.d: extern(C){ export void test(){} } so.c: static void _init(void) __attribute__((constructor)); static void _fini(void) __attribute__((destructor)); void gc_init(); void gc_term(); void _minit(); void _moduleCtor(); void _moduleUnitTests(); void _init(void){ gc_init(); _minit(); _moduleCtor(); _moduleUnitTests(); } void _fini(void){ gc_term(); } /*** CODE END ***/ Compile: gcc -c so.c gdc -oTest.so so.o test.d -fPIC -shared It passed. But when load it, some errors happend: undefined symbol: _minit
Aug 15 2006
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)I try to write a ruby extension. In ruby, excute "require 'Test'", 'Test.so' will be loaded and function 'Init_Test' will be called.
Aug 15 2006