Re: Using D static library from C
You need to link the druntime too, I think.
Re: Using D static library from C
On Thursday, 5 June 2014 at 18:55:13 UTC, Stefan Koch wrote: You need to link the druntime too, I think. At which stage? Can you provide a full command? Thanks.
Re: Using D static library from C
You can create a static library from one or more .o files using ar, if that helps (unless I've failed to understand the question). ar r libtest.a test.o should do the job.
Re: Using D static library from C
On Thursday, 5 June 2014 at 19:00:24 UTC, George Sapkin wrote: On Thursday, 5 June 2014 at 18:55:13 UTC, Stefan Koch wrote: You need to link the druntime too, I think. At which stage? Can you provide a full command? Thanks. Err ... I just remeberd linking d with gcc needs a few libs -lpthread -lc -lm and possiby more though I use gdc I don't know what dmd links by default try to make an object file with gcc and link with dmd
Re: Using D static library from C
On Thursday, 5 June 2014 at 19:10:17 UTC, Dave Wilson wrote: You can create a static library from one or more .o files using ar, if that helps (unless I've failed to understand the question). ar r libtest.a test.o should do the job. I don't have trouble creating a static library with dmd, I have trouble figuring out how to link it with C using gcc.
Re: Using D static library from C
On Thursday, 5 June 2014 at 19:14:34 UTC, Stefan Koch wrote: On Thursday, 5 June 2014 at 19:00:24 UTC, George Sapkin wrote: On Thursday, 5 June 2014 at 18:55:13 UTC, Stefan Koch wrote: You need to link the druntime too, I think. At which stage? Can you provide a full command? Thanks. Err ... I just remeberd linking d with gcc needs a few libs -lpthread -lc -lm and possiby more though I use gdc I don't know what dmd links by default try to make an object file with gcc and link with dmd I can link a D object (not a static lib) with gcc using -lphobos2 and that works. So additional libs does not solve anything. The trouble is linking a static lib without causing a segfault.
Re: Using D static library from C
On Thursday, 5 June 2014 at 19:14:34 UTC, Stefan Koch wrote: On Thursday, 5 June 2014 at 19:00:24 UTC, George Sapkin wrote: On Thursday, 5 June 2014 at 18:55:13 UTC, Stefan Koch wrote: You need to link the druntime too, I think. At which stage? Can you provide a full command? Thanks. Err ... I just remeberd linking d with gcc needs a few libs -lpthread -lc -lm and possiby more though I use gdc I don't know what dmd links by default try to make an object file with gcc and link with dmd I can link a D object (not a static lib) with gcc using -lphobos2 and that works. So additional libs does not solve anything. The trouble is linking a static lib without causing a segfault.
Re: Using D static library from C
I found that if I told dmd rather than gcc to do the linking that everything just magically worked. In other words: gcc -c cstuff.c dmd -c dstuff.d dmd cstuff.o dstuff.o I presume that dmd would be similarly smart with static libraries.
Re: Using D static library from C
On Friday, 6 June 2014 at 02:01:12 UTC, Mark Isaacson wrote: I found that if I told dmd rather than gcc to do the linking that everything just magically worked. In other words: gcc -c cstuff.c dmd -c dstuff.d dmd cstuff.o dstuff.o I presume that dmd would be similarly smart with static libraries. Yes, but I need to integrate this with gcc project. To get around phobos2 being linked twice and still have a static lib suitable for gcc I'm trying this now: dmd -c test.d ar r libtest.a test.o gcc main.c -ltest -L. -lphobos2 -otest It works with this small test project. I'll try to integrate this into bigger project now.
Re: Using D static library from C
On Thursday, 5 June 2014 at 18:51:25 UTC, George Sapkin wrote: I'm trying to link a simple D static library to C code, but I'm can't figure out how to do it properly without getting a segfault when running it. try this: dmd -lib test.d -defaultlib=libphobos2.a -oflibtest.a gcc main.c libtest.a -l:libphobos2.a -lpthread -lm -lrt
Re: Using D static library from C
On Friday, 6 June 2014 at 02:13:08 UTC, Ellery Newcomer wrote: On Thursday, 5 June 2014 at 18:51:25 UTC, George Sapkin wrote: I'm trying to link a simple D static library to C code, but I'm can't figure out how to do it properly without getting a segfault when running it. try this: dmd -lib test.d -defaultlib=libphobos2.a -oflibtest.a gcc main.c libtest.a -l:libphobos2.a -lpthread -lm -lrt Awesome! That works! Thanks. So is dmd linking to shared/different phobos2 by default or something?
Re: Using D static library from C
On Friday, 6 June 2014 at 02:17:50 UTC, George Sapkin wrote: On Friday, 6 June 2014 at 02:13:08 UTC, Ellery Newcomer wrote: On Thursday, 5 June 2014 at 18:51:25 UTC, George Sapkin wrote: I'm trying to link a simple D static library to C code, but I'm can't figure out how to do it properly without getting a segfault when running it. try this: dmd -lib test.d -defaultlib=libphobos2.a -oflibtest.a gcc main.c libtest.a -l:libphobos2.a -lpthread -lm -lrt Awesome! That works! Thanks. So is dmd linking to shared/different phobos2 by default or something? yeah, -defaultlib=libphobos2.so is the other option, I guess it's default now.