Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
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. test.d --- import std.stdio; extern(C) void funcD() { writeln(From D); } main.c ---

Re: Using D static library from C

2014-06-05 Thread Stefan Koch via Digitalmars-d-learn
You need to link the druntime too, I think.

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
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

2014-06-05 Thread Dave Wilson via Digitalmars-d-learn
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

2014-06-05 Thread Stefan Koch via Digitalmars-d-learn
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

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
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

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
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

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
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

Re: Using D static library from C

2014-06-05 Thread Mark Isaacson via Digitalmars-d-learn
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

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
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

Re: Using D static library from C

2014-06-05 Thread Ellery Newcomer via Digitalmars-d-learn
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

Re: Using D static library from C

2014-06-05 Thread George Sapkin via Digitalmars-d-learn
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

Re: Using D static library from C

2014-06-05 Thread Ellery Newcomer via Digitalmars-d-learn
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