caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Compiling C++ in OCaml using Swig to native code
@ 2009-06-09 11:36 Tautrimas Pajarskas
  2009-06-21 12:46 ` [Caml-list] " Guillaume Yziquel
  0 siblings, 1 reply; 3+ messages in thread
From: Tautrimas Pajarskas @ 2009-06-09 11:36 UTC (permalink / raw)
  To: caml-list

Hello,

I'm trying to access C++ code from OCaml using Swig. I successfully
compiled C++ code as a shared library through swig's C++ wrapper but
only in bytecode. Now, if I try the procedures listed in
http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php#ref_cplusplus
for ocamlopt, I get an error:

ocamlopt -I . -cclib -lstdc++ md5wrapper.x.cmxa caller.ml -o caller.native
./libmd5wrapper.x.a(md5wrapper_wrap.o): In function
`_wrap_new_md5wrappermd5wrapper':
md5wrapper_wrap.cxx:(.text+0x147a): undefined reference to
`md5wrapper::md5wrapper()'
./libmd5wrapper.x.a(md5wrapper_wrap.o): In function
`_wrap_delete_md5wrappermd5wrapper':
md5wrapper_wrap.cxx:(.text+0x2d20): undefined reference to
`md5wrapper::~md5wrapper()'
./libmd5wrapper.x.a(md5wrapper_wrap.o): In function
`_wrap_md5wrapper_getHashFromStringmd5wrapper':
md5wrapper_wrap.cxx:(.text+0x7742): undefined reference to
`md5wrapper::getHashFromString(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status
File "caml_startup", line 1, characters 0-1:
Error: Error during linking
make: *** [caller.native] Error 2

Library consists of two files: md5wrapper.h (main interface), md5.h,
and their appropriate cpp files.
md5wrapper_wrap.cxx is the swig's generated wrapper and
md5wrapper.x.cmxa is the shared library.
caller.ml is the script for using Md5wrapper module (library?).
Here is the Makefile: http://pastebin.com/f5f55f789 (Keep in mind that
caller.byte target compiles perfectly).

I've tried all the variants I could think of. If anybody has any
experience in Swig, please help (:

--
Tautrimas Pajarskas


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Compiling C++ in OCaml using Swig to native code
  2009-06-09 11:36 Compiling C++ in OCaml using Swig to native code Tautrimas Pajarskas
@ 2009-06-21 12:46 ` Guillaume Yziquel
  2009-06-22 10:46   ` Tautrimas Pajarskas
  0 siblings, 1 reply; 3+ messages in thread
From: Guillaume Yziquel @ 2009-06-21 12:46 UTC (permalink / raw)
  To: Tautrimas Pajarskas; +Cc: caml-list

Tautrimas Pajarskas a écrit :
> Hello,

Hello.

> I'm trying to access C++ code from OCaml using Swig. I successfully
> compiled C++ code as a shared library through swig's C++ wrapper but
> only in bytecode. Now, if I try the procedures listed in
> http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php#ref_cplusplus
> for ocamlopt, I get an error:

I'm sorry I can't help you, but you can help me: I'm also interested in 
binding C++ code to OCaml. Could I have a look at what you did so that I 
can have some guidance as to how to bind C++ code? I'd be perfectly 
happy with bytecode...

> Tautrimas Pajarskas

All the best,

Guillaume Yziquel.

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Compiling C++ in OCaml using Swig to native code
  2009-06-21 12:46 ` [Caml-list] " Guillaume Yziquel
@ 2009-06-22 10:46   ` Tautrimas Pajarskas
  0 siblings, 0 replies; 3+ messages in thread
From: Tautrimas Pajarskas @ 2009-06-22 10:46 UTC (permalink / raw)
  To: guillaume.yziquel; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1178 bytes --]

On Sun, Jun 21, 2009 at 3:46 PM, Guillaume Yziquel <
guillaume.yziquel@citycable.ch> wrote:

>
>  Hello.
>
>  I'm trying to access C++ code from OCaml using Swig. I successfully
>> compiled C++ code as a shared library through swig's C++ wrapper but
>> only in bytecode. Now, if I try the procedures listed in
>>
>> http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php#ref_cplusplus
>> for ocamlopt, I get an error:
>>
>
> I'm sorry I can't help you, but you can help me: I'm also interested in
> binding C++ code to OCaml. Could I have a look at what you did so that I can
> have some guidance as to how to bind C++ code? I'd be perfectly happy with
> bytecode...


You can have a look at the Makefile (http://pastebin.com/f5f55f789). If you
follow caller.byte (which is made from a simple ocaml source file for
calling c++ function from compiled library called md5wrapper.cma) you will
have all the instructions required to compile c++ library md5wrapper.cpp for
ocaml. For me, it was a good example of how to use multiple files with
bytecode. Native code still doesn't work and I still seek help.
If there is something unclear, just ask.

-- 
Tautrimas Pajarskas

[-- Attachment #2: Type: text/html, Size: 1780 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-06-22 10:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-09 11:36 Compiling C++ in OCaml using Swig to native code Tautrimas Pajarskas
2009-06-21 12:46 ` [Caml-list] " Guillaume Yziquel
2009-06-22 10:46   ` Tautrimas Pajarskas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).