C++ objects to OCaml objects.

View: New views
4 Messages — Rating Filter:   Alert me  

C++ objects to OCaml objects.

by Guillaume Yziquel-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello.

I'm currently trying to bind a C++ library. More specifically, I'm
trying to map C++ objects and classes to OCaml objects and classes.

What's the best way to do it? Any code samples around?

All the best,

Guillaume Yziquel.

------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: C++ objects to OCaml objects.

by Miklos Vajna :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Jun 21, 2009 at 03:03:20PM +0200, Guillaume Yziquel <guillaume.yziquel@...> wrote:
> What's the best way to do it? Any code samples around?

I would start with the examples:

http://swig.svn.sourceforge.net/viewvc/swig/trunk/Examples/ocaml/


------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

attachment0 (204 bytes) Download Attachment

Re: C++ objects to OCaml objects.

by Guillaume Yziquel-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Miklos Vajna a écrit :
> On Sun, Jun 21, 2009 at 03:03:20PM +0200, Guillaume Yziquel <guillaume.yziquel@...> wrote:
>> What's the best way to do it? Any code samples around?
>
> I would start with the examples:
>
> http://swig.svn.sourceforge.net/viewvc/swig/trunk/Examples/ocaml/

Thanks for the link. I already noticed that.

I managed to link a few pieces of C++ and OCaml. Not yet very
satisfying, but a good start.

However, I see a major shortcoming of Swig when it comes to OCaml:

I cannot find a "real" binding of C++ code with OCaml. I mean by that in
Objective Caml, there are .cmo bytecode object files, .cma bytecode
library files, .cmx native object files, .cmxa native library files, and
.cmxs native shared library files. I do not yet see a way to get to this
result when looking at the examples. I do not believe to be alone in
this situation since there has been a post on the OCaml mailing list of
someone managing to get a bytecode binding going, but not the native
binding...

So, has anyone used Swig to make an OCaml .cm[x]a library?

All the best,

Guillaume Yziquel.

------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Compiling Swig OCaml bindings.

by Guillaume Yziquel-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Guillaume Yziquel a écrit :
>
> So, has anyone used Swig to make an OCaml .cm[x]a library?
>
> All the best,
>
> Guillaume Yziquel.

I do not see what I am doing wrong:

> yziquel@seldon:~/svn/main/libmorfo-ocaml$ make 2>& 1 | grep -v warning | grep -v Warning
> swig -ocaml -c++ freeling.i
> cp freeling_wrap.cxx freeling_wrap.cxx.c
> ocamlc -c swig.mli
> ocamlc -c swig.ml
> File "swig.ml", line 159, characters 54-57:
> gcc -Wall -fPIC -O2 -I/usr/include -I/usr/lib/ocaml/3.11.0 -I/usr/lib -c -xc++ freeling_wrap.cxx.c
> freeling_wrap.cxx.c: In function ‘caml_value_t _wrap_new_tokenizerfreeling(caml_value_t)’:
> freeling_wrap.cxx.c: In function ‘caml_value_t _wrap_tokenizer_tokenize__SWIG_0freeling(caml_value_t)’:
> freeling_wrap.cxx.c: In function ‘caml_value_t _wrap_tokenizer_tokenize__SWIG_1freeling(caml_value_t)’:
> freeling_wrap.cxx.c: In function ‘caml_value_t _wrap_tokenizer_tokenizefreeling(caml_value_t)’:
> freeling_wrap.cxx.c: In function ‘caml_value_t _wrap_delete_tokenizerfreeling(caml_value_t)’:
> freeling_wrap.cxx.c: At global scope:
> ocamlc -c freeling.mli
> ocamlc -c freeling.ml
> File "freeling.ml", line 51, characters 13-14:
> ar rcs libfreeling_stubs.a freeling_wrap.cxx.o
> ocamlmklib -o freeling_stubs freeling_wrap.cxx.o
> ocamlc -a -dllib dllfreeling_stubs.so -cclib -lfreeling_stubs -cclib -lpcre -o freeling.cma -custom freeling.cmo swig.cmo
> yziquel@seldon:~/svn/main/libmorfo-ocaml$ ocaml freeling.cma
> Cannot load required shared library dllfreeling_stubs.
> Reason: ./dllfreeling_stubs.so: ./dllfreeling_stubs.so: undefined symbol: pcre_free.

And the files:

> yziquel@seldon:~/svn/main/libmorfo-ocaml$ ls
> freeling.i  Makefile  swig.ml  swig.mli

> yziquel@seldon:~/svn/main/libmorfo-ocaml$ cat freeling.i
> %module freeling
> %{
> #include "freeling.h"
> #include <pcre.h>
> %}
>
> class tokenizer {
>    public:
>        /// Constructor
>        tokenizer(const std::string &);
>
>        /// tokenize string with default options
>        std::list<word> tokenize(const std::string &);
>        /// tokenize string with default options, tracking offset in given int param.
>        std::list<word> tokenize(const std::string &, unsigned long &);
> };

> yziquel@seldon:~/svn/main/libmorfo-ocaml$ cat Makefile
> all:
> swig -ocaml -c++ freeling.i
> cp freeling_wrap.cxx freeling_wrap.cxx.c
> ocamlc -c swig.mli
> ocamlc -c swig.ml
> gcc -Wall -fPIC -O2 -I/usr/include -I/usr/lib/ocaml/3.11.0 -I/usr/lib -c -xc++ freeling_wrap.cxx.c
> ocamlc -c freeling.mli
> ocamlc -c freeling.ml
> ar rcs libfreeling_stubs.a freeling_wrap.cxx.o
> ocamlmklib -o freeling_stubs freeling_wrap.cxx.o
> ocamlc -a -dllib dllfreeling_stubs.so -cclib -lfreeling_stubs -cclib -lpcre -o freeling.cma -custom freeling.cmo swig.cmo
>
> clean:
> rm -Rf freeling.ml
> rm -Rf freeling.mli
> rm -Rf freeling_wrap.cxx
> rm -Rf freeling_wrap.cxx.c
> rm -Rf freeling.cmi
> rm -Rf freeling.cmo
> rm -Rf freeling_wrap.cxx.o
> rm -Rf swig.cmi
> rm -Rf swig.cmo
> rm -Rf freeling.cma
> rm -Rf libfreeling_stubs.a
> rm -Rf dllfreeling_stubs.so



------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user