Linking C++ with a D-library

Adam D. Ruppe destructionator at gmail.com
Wed Jun 26 17:23:42 PDT 2013


On Thursday, 27 June 2013 at 00:00:23 UTC, Milvakili wrote:
> What about the other way around. If I linked them with dmd in 
> that case it throws errors due to <iostream>, what should I do 
> in that case?

I don't think you need to do any special C++ initialization, any 
needed work there is automatically inserted by the linker.

Just make sure you link with -L-lstdc++ if you're linking with 
dmd on Linux and the needed c++ lib should be pulled in.

Or if you want to link with g++ or ld, you'll want to link in 
-lphobos2 to get the D standard library.

Running dmd -v can be helpful to see exactly what is going on:

$ dmd -v test.d
< snip a lot of stuff >
gcc test25.o -o test25 -m32 
-L/home/me/d/dmd2/linux/bin32/../lib32 
-L/home/me/d/dmd2/linux/bin32/../lib64 -Xlinker 
--no-warn-search-mismatch -Xlinker --export-dynamic 
-l:libphobos2.a -lpthread -lm -lrt
$


Right at the end, you can see the command dmd is running to do 
the link. It uses gcc here, passing a bunch of libraries D will 
need.



But if you just let dmd do the link you can add C++ libraries 
with -L-l.


More information about the Digitalmars-d mailing list