Thread overview
linking druntime in when C calls D and C implements main()
Jul 27, 2012
Carl Sturtivant
Jul 27, 2012
Carl Sturtivant
Jul 27, 2012
Johannes Pfau
Jul 27, 2012
Carl Sturtivant
July 27, 2012
If I separately compile dfunc.d containing an exern(C) function, and cmain.c containing void main() that calls that function (after calling rt_init() to initialize druntime) and then ask dmd to link the resulting pair of objects into an executable, the linker complains that various symbols (including _rt_init) are not present, suggesting that (quite reasonably) dmd does not place druntime inside an arbitrary d object file. How to I ask dmd to link in druntime so as to get a working executable in this situation exemplifying a C application calling a D library function with C linkage?
July 27, 2012
Answer my own question: it seems that an explicit mention of
phobos also brings in druntime so now linking works (new to this: thought those were two separate things).

July 27, 2012
Am Fri, 27 Jul 2012 20:07:32 +0200
schrieb "Carl Sturtivant" <sturtivant@gmail.com>:

> Answer my own question: it seems that an explicit mention of phobos also brings in druntime so now linking works (new to this: thought those were two separate things).
> 

They _are_ different projects, but we currently ship a libphobos2.a which already contains libdruntime.a. But if you build druntime yourself you'll get a libdruntime.a which can be used without phobos.

IIRC some time ago we shipped druntime & phobos as single libraries, but that was changed for some reason. Once druntime & phobos work as shared libraries we'll probably have to separate them again.


July 27, 2012
> They _are_ different projects, but we currently ship a libphobos2.a which already contains libdruntime.a. But if you build druntime yourself you'll get a libdruntime.a which can be used without
> phobos.

Thanks, good to know. My post was misleading though, apologies; I do want phobos --- I like its style & it's great for my purposes.