www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Problems linking with C++ using g++?

reply Nick <Nick_member pathlink.com> writes:
I'm trying to build a simple interface between D with C++. I've made the
following short test:

-- dtest.d --
import std.stdio;
extern(C) void cfunc();
extern(C) void dfunc() {}
void main() { cfunc(); }

-- ctest.cpp --
extern "C" void dfunc();
extern "C" void cfunc() { dfunc(); }

Compiling:
$ g++ -c ctest.cpp
$ dmd dtest.d ctest.o
gives the linker error:
tmp.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'

Does anybody have any hints? It works perfectly if I rename .cpp to .c and use
gcc instead. I have gcc 4.0.2.

Nick
Nov 07 2005
parent reply Nick <Nick_member pathlink.com> writes:
In article <dkoiic$nnc$1 digitaldaemon.com>, Nick says...
[...]
$ g++ -c ctest.cpp
$ dmd dtest.d ctest.o
gives the linker error:
tmp.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
Nevermind, I found the answer. The problem is that dmd uses gcc to link, not g++, and that may cause some problems when linking c++ programs. For some reason it worked with my actual program once I tested it. Anyway, the safest solution (in case anyone stumbles onto this later) is to link using g++, not dmd. Nick
Nov 07 2005
parent reply R'emy Mou:eza <R'emy_member pathlink.com> writes:
In article <dkoiic$nnc$1 digitaldaemon.com>, Nick says...
[...]
$ g++ -c ctest.cpp
$ dmd dtest.d ctest.o
gives the linker error:
tmp.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
Nevermind, I found the answer. The problem is that dmd uses gcc to link, not g++, and that may cause some problems when linking c++ programs.
You may need to link with the libstdc++ if you're working with both g++ and dmd. I also made a tool to wrap C++ header files to D and when I was working with gdc it would not work unless I use the -lstdc++ flag.
Nov 08 2005
parent Robert Jones <robertjones21 HotPOP.com> writes:
R'emy Mou:eza said the following on 11/8/2005 3:22 AM:
 In article <dkoiic$nnc$1 digitaldaemon.com>, Nick says...
 [...]
 $ g++ -c ctest.cpp
 $ dmd dtest.d ctest.o
 gives the linker error:
 tmp.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
Nevermind, I found the answer. The problem is that dmd uses gcc to link, not g++, and that may cause some problems when linking c++ programs.
You may need to link with the libstdc++ if you're working with both g++ and dmd. I also made a tool to wrap C++ header files to D and when I was working with gdc it would not work unless I use the -lstdc++ flag.
how usable is that tool and where can i get it?
Dec 14 2005