Bug 6121 – Can't link with DMC C++ generated functions with long arguments

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-06-07T11:11:00Z
Last change time
2015-06-09T05:15:05Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2011-06-07T11:11:04Z
foo.d: extern(C++) void test(int); void main() { test(1); } bar.cpp: void test(long) { }; $ dmc -c -cpp bar.cpp $ dmd foo.d bar.obj http://www.digitalmars.com/ctg/optlink.html foo.obj(foo) Error 42: Symbol Undefined ?test@@YAXH@Z (void cdecl test(int )) Symbol reference in foo.obj (D): ?test@@YAXH@Z Symbol in bar.obj (CPP): ?test@@YAXJ@Z According to this page: http://www.digitalmars.com/ctg/ctgMemoryModel.html , long in DMC has the same size as int in D. I've tried various other types but nothing works. Only if I change bar.cpp's test to: void test(int){} then it will compile and link. So how am I supposed to link with C++ functions that take a long if I can't change them? Due to this bug I can't link DDMD with the backend of DMD 2.053. Also, your DMC echoes 8.42n instead of 8.52c, fyi.
Comment #1 by issues.dlang — 2011-06-11T15:30:54Z
I believe that that's why druntime uses the alias c_long.
Comment #2 by andrej.mitrovich — 2011-06-11T15:50:12Z
Right, c_long is an alias to int on Windows. It still won't link, but a comment in another thread might lead me to believe that this is just a name-mangling problem.
Comment #3 by yebblies — 2011-06-12T05:08:33Z
This _is_ a name mangling problem. D's long is not the same as C's long (at least not on x86) and should not be mangled the same. There is currently no way to have dmd mangle a C or C++ function with a C long argument. As dmd is working as designed, I'm going to close this as invalid. You should reopen as an enhancement request if you think dmd should be changed to do things differently. (There is also already an enhancement request issue 2698 which would solve your problem)