using D with C++

Nical nical.silva at gmail.com
Mon Mar 8 00:49:37 PST 2010


Hi, I'm trying to use C/C++ functions in a D program but I cant get
it to compile.
I tried the exemple of digital mars's website:

// ---- file.cpp
#include <iostream>
using namespace std;
int foo(int i, int j, int k)
{
    cout << "i = " << i << endl;
    cout << "j = " << j << endl;
    cout << "k = " << k << endl;
    return 7;
}

// ---- main.d
extern (C++) int foo(int i, int j, int k);
void main()
{
    foo(1,2,3);
}

and a makefile that might not be correct now that i've experimented
various things on it:

OBJ= main.o file.o

all: ${OBJ}
	g++ ${OBJ}

bin/main.o: file.o
	dmd main.d

bin/file.o:
	g++ -c file.cpp -o file.o



I get this error:

nico at nical-netbook:~/Programmation/D/test binding$ make
g++    -c -o file.o file.cpp
g++ main.o file.o -o test
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o: In
function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115:
undefined reference to `main'
main.o: In function `no symbol':
main.d:(.text+0x8): undefined reference to `_Dmodule_ref'
collect2: ld returned 1 exit status
make: *** [all] Erreur 1
nico at nical-netbook:~/Programmation/D/test binding$

thanks in advance

Nico


More information about the Digitalmars-d-learn mailing list