Hi
I just spent a bit of time looking for this, i.e., how to get a CFFI for a C++ library, but at this point I am not so sure about the best way to go about this.
What is the wisdom of the list on the subject?
Thanks
Marco
-- Marco Antoniotti, Associate Professor tel. +39 - 02 64 48 79 01 DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it Viale Sarca 336 I-20126 Milan (MI) ITALY
Please check: http://cdac.lakecomoschool.org
Please note that I am not checking my Spam-box anymore. Please do not forward this email without asking me first.
I use cl-autowrap[1], which uses c2ffi[2] to create "definitions from C, C++, and Objective C headers for use with foreign function call interfaces".
it uses CFFI-SYS, and I have only tested it out using C++ libs, but it should work for most things most of the time. I am not sure if it is the best way, but, I did it my way[3].
Cheers,
Drew Crampsie
[1] https://github.com/rpav/cl-autowrap [2] https://github.com/rpav/c2ffi [3] https://www.youtube.com/watch?v=WIXg9KUiy00
On Sun, Jun 5, 2016 at 1:56 PM, Antoniotti Marco < antoniotti.marco@disco.unimib.it> wrote:
Hi
I just spent a bit of time looking for this, i.e., how to get a CFFI for a C++ library, but at this point I am not so sure about the best way to go about this.
What is the wisdom of the list on the subject?
Thanks
Marco
-- Marco Antoniotti, Associate Professor tel. +39 - 02 64 48 79 01 DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it Viale Sarca 336 I-20126 Milan (MI) ITALY
Please check: http://cdac.lakecomoschool.org
Please note that I am not checking my Spam-box anymore. Please do not forward this email without asking me first.
On Sun, Jun 05, 2016 at 03:39:38PM -0700, Drew C wrote:
I use cl-autowrap[1], which uses c2ffi[2] to create "definitions from C, C++, and Objective C headers for use with foreign function call interfaces".
it uses CFFI-SYS, and I have only tested it out using C++ libs,
That's interesting, coul you elaborate a bit? I was under the impression that such a straight ffi would be impossible (thanks to C++'s name mangling). I on't see how c2ffi can cope with the following valid C++:
|----------------[ file: foo.h ]-------------------------------------------
int do_something(int input);
int do_something(char *input);
|--------------------------------------------------------------------------
And, indeed, my fresh checkout of c2ffi complaints bitterly :-/ The next problem would be the fact that the output of C++ compilers still isn't really ABI-compatible.
but it should work for most things most of the time. I am not sure if it is the best way, but, I did it my way[3].
The only real working wrapper for C++ libs (Qt4) are the wrappers based on KDE projects smoke based binings. But those need "auto"[1]-generated wrapper libraries ... So, to wrap your own libraries you'd need to generate smoke wrappers. Doable but not simple.
HTH Ralf Mattes
[1] For a very broad definition of "auto"
Cheers,
Drew Crampsie
[1] https://github.com/rpav/cl-autowrap [2] https://github.com/rpav/c2ffi [3] https://www.youtube.com/watch?v=WIXg9KUiy00
On Sun, Jun 5, 2016 at 1:56 PM, Antoniotti Marco < antoniotti.marco@disco.unimib.it> wrote:
Hi
I just spent a bit of time looking for this, i.e., how to get a CFFI for a C++ library, but at this point I am not so sure about the best way to go about this.
What is the wisdom of the list on the subject?
Thanks
Marco
-- Marco Antoniotti, Associate Professor tel. +39 - 02 64 48 79 01 DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it Viale Sarca 336 I-20126 Milan (MI) ITALY
Please check: http://cdac.lakecomoschool.org
Please note that I am not checking my Spam-box anymore. Please do not forward this email without asking me first.
Le 6 juin 2016 à 09:33, Ralf Mattes rm@seid-online.de a écrit :
I was under the impression that such a straight ffi would be impossible (thanks to C++'s name mangling). I on't see how c2ffi can cope with the following valid C++:
It would be possible. Name mangling only means that the actual name of the functions are not what is witten is the program source. Unfortunately, the actual mangling is C++ compiler dependant, so you would have to reproduce the algorithm for each C++compiler you would want to support. Alternatively, you can just look up the symbols in the libraries themselves, but this would be more a manual approach to match the right mangled symbol with the right polymorphic function, if you don't know the mangling rule.
On the other hand, AFAIK, clang implements the same mangling as gcc, so implementing it for your ffi would already cover 99% of the cases.
On Sun, Jun 5, 2016 at 4:56 PM, Antoniotti Marco antoniotti.marco@disco.unimib.it wrote:
Hi
I just spent a bit of time looking for this, i.e., how to get a CFFI for a C++ library, but at this point I am not so sure about the best way to go about this.
What is the wisdom of the list on the subject?
1- Look at c2ffi support for cffi, recently added by Attila Lendvai. 2- and/or look at the FFI in CLASP, based on the LLVM.
—♯ƒ • François-René ÐVB Rideau •Reflection&Cybernethics• http://fare.tunes.org It’s amazing that the amount of news that happens in the world everyday always just exactly fits the newspaper.
1- Look at c2ffi support for cffi, recently added by Attila Lendvai.
this will not work out of the box for C++, but it has paved the way for auto generating a C file with wrapper definitions, which then can be auto-bridged into lisp with cffi/c2ffi.
C++ poses similar issue like inline C functions in header files, they also need a C wrapper to be able to bind them into lisp. so, to make cffi/c2ffi 100% even for plain C, it still needs a wave of work to also generate a CFFI grovel file for stuff like C inline functions.
but i think it's still a long way from there to have any reasonable auto generated bindings for C++, so i gave up on C++.
if you badly need to work with C++ from lisp then clasp may be a better environment, if it's already stable enough for your needs.