On Monday, 16 March 2020 at 07:46:00 UTC, drug wrote:
On 3/16/20 10:11 AM, Ferhat Kurtulmuş wrote:
On Sunday, 15 March 2020 at 22:25:27 UTC, Arine wrote:
On Sunday, 15 March 2020 at 21:27:32 UTC, Ferhat Kurtulmuş

extern(C++, cv){
extern(C++, class) struct Size_(_Tp){
    @disable this();
    ~this() { }

    final _Tp area() const;
    final double aspectRatio() const;
    final bool empty() const;

    _Tp width; //!< the width
    _Tp height; //!< the height
}
}

extern(C++){
    cv.Size_!int* createSizeIntWH(int w, int h);
}

void main()
{
    Size_!int* sz = createSizeIntWH(200, 100);
    writeln(sz.width);
}

This worked for me too. But member functions are still causing linker error. It seems like docs (https://dlang.org/spec/cpp_interface.html) do not cover those situations. Is there any other sources to read for it. Maybe you make a pull request to docs covering C++ interfacing tips in detail.

Not tested:

 extern(C++, class) struct Size_(_Tp){
     @disable this();
     ~this() { }
extern(C++): // <- IIRC linkage should be set for members separately from aggregate
     final _Tp area() const;
     final double aspectRatio() const;
     final bool empty() const;

     _Tp width; //!< the width
     _Tp height; //!< the height
 }

Ok, here is a solution. I opened my lib (yielded by my auxilary cpp) using 7zip. There are two files containing symbol names, 1.txt and 2.txt. I searched for names of member functions. They were not there because c++ compiler does not compile member functions of class templates because we don't actually use them. So, I simply include this line in my aux cpp file and recompiled it:

template class cv::Size_<int>;

I reopened 1.txt and they are there now:

?area@?$Size_@H@cv@@QEBAHXZ
?aspectRatio@?$Size_@H@cv@@QEBANXZ

now everything works :D

Reply via email to