Closed Alex-Shand closed 5 years ago
I recommend using the static stub generation (Cstubs
) rather than dynamic linking (Foreign
), since it makes linking much easier, among other advantages. However, sticking with your current approach, the following works for me:
$ wget -q -O - http://www.dyncall.org/r1.0/dyncall-1.0-arch_linux-2011.08.19-x64.tar.gz | tar xz
$ cat test.ml
open Ctypes
open Foreign
type dcCallVM = unit ptr
let dcCallVM : dcCallVM typ = ptr void
let dcNewCallVM = foreign "dcNewCallVM" (int @-> returning dcCallVM)
let vm = dcNewCallVM 4096
let () = Format.printf "dcNewCallVM 4096 => %a@." Ctypes.(format (ptr void)) vm
$ ocamlfind opt -cclib '-Wl,-E -Ldyncall-1.0-release/lib/ -Wl,-whole-archive -l:libdyncall_s.a -Wl,-no-whole-archive' -linkpkg -package ctypes.foreign test.ml -o dyncall_test
$ ./dyncall_test
dcNewCallVM 4096 => 0x55787a6ab2b0
Thank you, that works perfectly.
Hi,
I'm trying to write bindings for the dyncall static library (www.dyncall.org).
The build commands I've tried: is one of:
ocamlfind ocamlopt <x> -linkpkg -package ctypes.foreign test.ml -o dyncall_test
whereAnd test.ml contains:
In all cases the compilation completes without errors but running ./dyncall_test produces:
'Fatal error: exception Dl.DL_error("./dyncall_test: undefined symbol: dcNewCallVM")'
Other information: ocamlopt -v:
gcc -v:
Any advice would be appreciated.
Thanks, Alex