Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Compiling C++ in OCaml using Swig to native code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tautrimas Pajarskas <tautrimas@t...>
Subject: Compiling C++ in OCaml using Swig to native code

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
for ocamlopt, I get an error:

ocamlopt -I . -cclib -lstdc++ md5wrapper.x.cmxa -o caller.native
./libmd5wrapper.x.a(md5wrapper_wrap.o): In function
md5wrapper_wrap.cxx:(.text+0x147a): undefined reference to
./libmd5wrapper.x.a(md5wrapper_wrap.o): In function
md5wrapper_wrap.cxx:(.text+0x2d20): undefined reference to
./libmd5wrapper.x.a(md5wrapper_wrap.o): In function
md5wrapper_wrap.cxx:(.text+0x7742): undefined reference to
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. is the script for using Md5wrapper module (library?).
Here is the Makefile: (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