www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - linking druntime in when C calls D and C implements main()

reply "Carl Sturtivant" <sturtivant gmail.com> writes:
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?
Jul 27 2012
parent reply "Carl Sturtivant" <sturtivant gmail.com> writes:
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).
Jul 27 2012
parent reply Johannes Pfau <nospam example.com> writes:
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.
Jul 27 2012
parent "Carl Sturtivant" <sturtivant gmail.com> writes:
 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.
Jul 27 2012