Help learning how to interface with c(++)

Kagamin spam at here.lot
Tue Mar 8 23:23:28 PST 2011


Kai Meyer Wrote:

> gcc -m32 -shared -fPIC Test.cpp -o libTest.so

> So I monkeyed around a little bit, and found out that if I change 
> "extern (C)" to "extern (C++)", the library links correctly and the 
> program runs.
> 
> That lead me to believe that if I added the "-cpp" option to htod.exe, 
> it would generate extern(C++) functions. But I got a blank Test.d file 
> doing it that way.
> 
> So, gcc created a libTest.so with a function in it, and dmd only finds 
> the function with extern(C++) and not with extern(C).
> 
> Now I'm just confused, yet pleased something worked.

Because you compile .cpp file, gcc compiles it with g++ as C++ and mangles functions accordingly. You can tell gcc to compile the file as C.


More information about the Digitalmars-d-learn mailing list