digitalmars.D - shared objects
- rochus (6/6) Jan 08 2007 Hi,
- Christian Kamm (5/6) Jan 08 2007 Yes. I've only tried it with a single file, but it should work. Use dmd ...
- rochus (33/41) Jan 08 2007 Hi Christian,
- Witold Baryluk (6/13) Jan 08 2007 You must run /sbin/ldconfig, to update ld caches.
- rochus (7/12) Jan 08 2007 Sorry but that's not true. As long as the path (in this case,
- Christian Kamm (9/10) Jan 08 2007 Two things:
- rochus (5/17) Jan 08 2007 Hi Christian and: Thank you!
Hi, Is it possible to write shared objects for linux with DMD? If "yes", how would one do that - and if "no", when will DMD be able to compile to shared objects? BG Nicolai Waniek
Jan 08 2007
Is it possible to write shared objects for linux with DMD?Yes. I've only tried it with a single file, but it should work. Use dmd -c to compile without linking and then link manually with gcc <object-files> -shared <your flags> -o lib<name>.so. I hope that helps, Christian
Jan 08 2007
Christian Kamm wrote:Hi Christian, I gave it a try but I didn't succeed, maybe you could help me again: First i created the file "square.d": export int squareIt(int i) { return i*i; } I compiled and linked it with: dmd -c square.d gcc -shared -o libsquare.so libsquare.o I copied the library to /usr/local/lib (where ld may find it) Then i created another file just containing the function declaration ("libsquare.d"): export int squareIt(int i); The next step was writing a little sample app ("app.d"): import std.stdio; // now the important line: import the lib: import libsquare; void main(char[][] args) { writefln("4*4 = %d", squareIt(4)); } I tried to compile it this way: dmd app.d libsquare.d -L-lsquare But this gave me an error message: gcc app.o libsquare.o -o app -m32 -lphobos -lm -Xlinker -lsquare app.o: In function '_Dmain': app.d:(.gnu.linkonce.t_Dmain+0xa): undefined reference to '_imp__D9libsquare8squareItFiZi' collect2: ld returned 1 exit status --- errorlevel 1 As I'm new to shared objects under linux, I don't know how to proceed right now. NicolaiIs it possible to write shared objects for linux with DMD?Yes. I've only tried it with a single file, but it should work. Use dmd -c to compile without linking and then link manually with gcc <object-files> -shared <your flags> -o lib<name>.so. I hope that helps, Christian
Jan 08 2007
On Mon, 08 Jan 2007 21:18:32 +0100rochus <rochus rochus.net> wrote:Christian Kamm wrote:I compiled and linked it with: dmd -c square.d gcc -shared -o libsquare.so libsquare.o I copied the library to /usr/local/lib (where ld may find it) ...You must run /sbin/ldconfig, to update ld caches. -- Witold Baryluk MAIL: baryluk smp.if.uj.edu.pl, baryluk mpi.int.pl JID: movax jabber.autocom.pl
Jan 08 2007
Witold Baryluk wrote:On Mon, 08 Jan 2007 21:18:32 +0100rochus <rochus rochus.net> wrote: You must run /sbin/ldconfig, to update ld caches.Sorry but that's not true. As long as the path (in this case, /usr/local/lib) is somewhere noted within ld.so.conf this path will be searched when a user wants to link against a library. Nevertheless, I gave it a try and called ldconfig - it didn't work. best regards, Nicolai
Jan 08 2007
I gave it a try but I didn't succeed, maybe you could help me again:Two things: First, remove the 'export'. For me, it doesn't work with it. Second, you defined a square.squareIt in your libsquare.so, but try to access it as libsquare.squareIt. Either put a 'module libsquare;' statement in square.d or use D's interface files: dmd -H should create such a file from your square.d. Then the compiler will use it when compiling with dmd app.d -L-lsquare. Cheers, Christian
Jan 08 2007
Christian Kamm wrote:Hi Christian and: Thank you! After omitting "export" and renaming everything to "libsquare.d", it worked. cheers! NicolaiI gave it a try but I didn't succeed, maybe you could help me again:Two things: First, remove the 'export'. For me, it doesn't work with it. Second, you defined a square.squareIt in your libsquare.so, but try to access it as libsquare.squareIt. Either put a 'module libsquare;' statement in square.d or use D's interface files: dmd -H should create such a file from your square.d. Then the compiler will use it when compiling with dmd app.d -L-lsquare. Cheers, Christian
Jan 08 2007