Вопрос

I want to use LEAP Motion in D.
Therefore It doesn't have C library and It has only C++ library.
I tried SWIG 2.0.9 below command.

swig -c++ -d -d2 leap.i 

This command output Leap.d, Leap_im.d, Leap_wrap.cxx, Leap_wrap.h.
However, I don't know how to use to wrapper in D and I can't find how to use the wrapper.
Link error displays to use it intact.
How use these wrapper in D2?
And can I use without Leap.cpp (source of Leap.dll)?

Update:

Thanks two answers. and sorry for reply late because of busy.
Say first conclusion I could build Leap sample code on Win64 by following the steps below.

  1. Output wrappers by above command.
  2. Create x64 DLL with VC2010 from Leap_wrap.cxx, Leap_wrap.h, and import Leap.lib(x64).
  3. Compile Leap.d and Leap_im.d with dmd -c.
  4. Build LeapTest.d with Leap.obj and Leap_im.obj

all command is below.

swig -c++ -d -d2 leap.i
dmd -c Leap.d Leap_im.d -m64
dmd LeapTest.d Leap.obj Leap_im.obj -m64
execute LeapTest.exe (require x64 Leap.dll and Leap_wrap.dll)

I could run Leap Program.
But program crach onFrame event callback.
I'll try again on x86 and investigate the causes.

Это было полезно?

Решение

Few helpful links (some information may be outdated):

I have never used SWIG personally but my guess based on general knowledge about SWIG:

  • Leap_wrap.cxx is C++ source file that wraps calls to C++ functions from target library in extern(C) calls
  • Leap_wrap.h is header file with all extern(C) wrappers listed
  • Leap_im.d is D module based on Leap_wrap.h with same extern(C) function listed
  • Leap.d is D module that uses Leap_im.d as an implementation and reproduces API similar to original C++ one.

So in your D code you want to import Leap.d module. Than compile Leap_wrap.cxx to an object file with your C++ compiler and provide D object files, Leap_wrap.o and target library at linking stage. That should do the trick.

P.S. Leap.cpp source should not be needed. All stuff links directly from Leap_wrap.cxx to target library binary.

Другие советы

Go to IRC, either FreeNode, or OFTC, channel #D. In order to help you, we have to see what is in those files. My first guess is that you have to compile both D files, and the C++ file into object files, and link them together. I suppose SWIG is going to flatten the C++ API into bunch of C functions, and that is probably what Leap_wrap.cxx does.

If the LEAP API is not complex (ie. just bunch of simple C++ classes), it may be possible to directly interface with it. Read more about it here: http://dlang.org/cpp_interface.html .

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top