www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

D.gnu - Linking with object file compiled with g++

Hi

I have started to use the SWIG with DMD (see the last posting.
This makes it possible to interface to an existing class written in C++
from D.
This may not be what was intended, but it has now become possible.
SWIG generates automatically a code layer which is linked in C style
which goes between the D and C++ codes.

In order to use this it is necessary to compile and link all the
modules. Typically there will be the function bodies for the C++ code
(say example.cxx) the interface which will be example_wrap.cxx and some
d code e.g. example.d.  There will be an example application, say
app.d.  The natural thing is to compile this with

g++ -c example.cxx
g++ -c example_wrap.cxx
dmd app.d example.d example_wrap.o example.o

Unfortunately, this does not work as dmd links with gcc rather than
g++.  It is necessary to compile all the modules e.g.

dmd -c app.d

(and make sure all the files have different names) and then link with
g++, which involves spelling out the D libraries

g++ app.o -oapp exampled.o example_wrap.o example.o -lphobos -lpthread
-lm

Could dmd for Linux have a flag -c++ which would mean that the link step
used g++ instead of gcc?  That way it could be done in one step.

Thanks

John Fletcher
Jun 03 2004