[Issue 17359] New: C++ Interfacing: function with 'static' array parameter cannot be linked (x64)
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Apr 28 12:41:26 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17359
Issue ID: 17359
Summary: C++ Interfacing: function with 'static' array
parameter cannot be linked (x64)
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: blocker
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ParticlePeter at gmx.de
C++ Interfacing: function with 'static' array parameter cannot be linked (x64)
C++ prototype:
bool cppFunc( float[3] color );
D binding (as described here [1])
extern(C++) bool cppFunc( ref float color );
Using with:
float[3] my_color;
cppFunc( my_color );
Building with dmd 2.0.73.1:
-> error LNK2001: unresolved external symbol "bool __cdecl cppFunc(float
(&)[3])" Binding.exe : fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120
dmd failed with exit code 1120.
Same problem but slightly different error messages with LDC.
The issue is discussed here in additional detail [2].
Summary:
Ali mentions that following variant works for him on linux:
"
// deneme.cpp
float cppFunc(float color[3]) {
return color[0] + color[1] + color[2];
}
$ g++ -c deneme.cpp -o deneme_cpp.o
// deneme.d
extern(C++) float cppFunc(float * color);
void main() {
float[3] my_color = [ 1.5, 2.5, 3.5 ] ;
assert(cppFunc(my_color.ptr) == 7.5);
}
$ dmd deneme_cpp.o deneme.d -of=deneme
"
Comment:
This varinat leads to the same compiler error (with "bool __cdecl
cppFunc(float*)" message) on windows compiled for x64.
kinke points out:
"
Microsoft's C++ compiler doesn't mangle `float arg[3]` parameters identically
to `float* arg`:
void cppSArray(float color[3]) => ?cppSArray@@YAXQEAM at Z
void cppPtr(float* color) => ?cppPtr@@YAXPEAM at Z
"
This contradicts Alis variant but not the 'ref' variant. But I belief that the
'ref' variant is also a mangling problem.
[1] http://dlang.org/spec/interfaceToC.html#passing_d_array
[2] https://forum.dlang.org/post/qcmrdrebuuhjfendyzud@forum.dlang.org
--
More information about the Digitalmars-d-bugs
mailing list