I tried to inteface between C++ and D.
The problem is that I can't compile it. I used the code/command line on the website
> g++ -c foo.cpp
> dmd bar.d foo.o -L-lstdc++ && ./bar
and it didn't work: first of all the DMD compiler doesn't use .o files so i had to specify manually to create a .obj file then the linker threw an error because it didn't knew /lstdc++ so i configured the cpp libs manually.
Thats the point where i am now it throws an "Symbol not found" error and i don't know how to fix this, am i doing something wrong on compiling? or is it on the programming site?
here my compile commands:
PS C:\Users\kunde\Downloads\d-interface test> g++ -c -o test-cpp.obj test.cpp
PS C:\Users\kunde\Downloads\d-interface test> dmd -L"G:\GNUstep\lib\gcc\mingw32\4.6.1\libstdc++.dll.a" -L"G:\GNUstep\lib\gcc\mingw32\4.6.1\libstdc++.a" .\test-cpp.obj .\test.d
test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""char __cdecl foo(int)" (?foo@@YADH@Z)" in Funktion "__Dmain".
test-cpp.exe : fatal error LNK1120: 1 nicht aufgelöste Externe
Error: linker exited with status 1120
and my code: test.d:
import std.stdio;
extern (C++) char foo(int i);
void main(string[] args)
{
writefln("%c", foo(14));
}
test.cpp:
#include <iostream>
extern "C" {
#include "test.h"
}
char foo(int i){
std::cout << "got: ";
return (char)bar(i);
}
and test.h:
#include <stdio.h>
int bar(int a){
printf("returned %d", a*a);
return a*a;
}
What am I doing wrong?
P.s.: im german so the errors may have to be translated
Edit: As sayd in the answers MSVC fixed the problem i changed "g++ -c -o test-cpp.obj test.cpp" to "cl test.cpp -c /EHsc"