Lisp HUG Maillist Archive

FLI/FFI between LWW and C++ dll

Hi,

I have already successfully called C functions in DLLs with LWW and the foreign-parser
is very useful in this area.

My new challenge requires to use a DLL compiled from lots of C++ files, and the headers make heavy use of namespaces.
Is there anything that I should be aware of which could ease the import and type definitions required to call those functions in the DLL?

- is there something that can handle name mangling of global functions more easily ?
- I guess that fli/ffi doesn't allow to map C++ objects into Lisp? Or did I miss something?

Thanks in advance and best regards,

-- 
Fabrice Popineau
-----------------------------
SUPELEC
Département Informatique
3, rue Joliot Curie
91192 Gif/Yvette Cedex
Tel direct : +33 (0) 169851950
Standard : +33 (0) 169851212
------------------------------

Re: FLI/FFI between LWW and C++ dll

Hi Fabrice,

The only solution I know is to call C functions that access the C++ library.
There are two approaches:

1. Wrap individual C++ classes,
2. Write high-level code that is custom to your application domain.

I found the first approach required more work and more time, and that it was not always possible to properly map C++ object model to CLOS.

A couple of other tricks:

- you might need to statically instantiate C++ templates so the interesting types are made available.
- use the famous "#ifdef __cplusplus ... #endif" macro in your C headers,
- ensure your C library uses a well defined convention call


Best,
Camille



On 29 Jan 2014, at 09:06, Fabrice Popineau <fabrice.popineau@supelec.fr> wrote:

> Hi,
> 
> I have already successfully called C functions in DLLs with LWW and the foreign-parser
> is very useful in this area.
> 
> My new challenge requires to use a DLL compiled from lots of C++ files, and the headers make heavy use of namespaces.
> Is there anything that I should be aware of which could ease the import and type definitions required to call those functions in the DLL?
> 
> - is there something that can handle name mangling of global functions more easily ?
> - I guess that fli/ffi doesn't allow to map C++ objects into Lisp? Or did I miss something?
> 
> Thanks in advance and best regards,
> 
> -- 
> Fabrice Popineau
> -----------------------------
> SUPELEC
> Département Informatique
> 3, rue Joliot Curie
> 91192 Gif/Yvette Cedex
> Tel direct : +33 (0) 169851950
> Standard : +33 (0) 169851212
> ------------------------------
> 


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: FLI/FFI between LWW and C++ dll

Hi! Try SWIG, http://www.swig.org

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: FLI/FFI between LWW and C++ dll

Thanks to Camille. I was merely at the point he described.
Thanks also to Denis because it seems that swig can help
http://www.swig.org/Doc1.3/Lisp.html
and I will try it !

Fabrice


2014-01-31 Denis Budyak <budden73@gmail.com>:
Hi! Try SWIG, http://www.swig.org



--
Fabrice Popineau
-----------------------------
SUPELEC
Département Informatique
3, rue Joliot Curie
91192 Gif/Yvette Cedex
Tel direct : +33 (0) 169851950
Standard : +33 (0) 169851212
------------------------------

Updated at: 2020-12-10 08:34 UTC