Hi list,

I'm running into a strange issue when compiling a ctypes (0.2.1) library with the -thread option. Here is my test program:

    open Ctypes
    open PosixTypes
    open Foreign

    let time = foreign "time" (ptr time_t @-> returning time_t)

    let _ = ignore (time (from_voidp time_t null))

This is the simplest example I could find from the ctypes tutorial. When I compile it without -threaded, it works:

$ ocamlfind ocamlopt -verbose -package ctypes,ctypes.foreign -linkpkg -o test test.ml
Effective set of compiler predicates: pkg_unix,pkg_bigarray,pkg_ctypes,pkg_ctypes.foreign-base,pkg_ctypes.foreign,autolink,native
+ ocamlopt.opt -verbose -o test -I /Users/mike/.opam/system/lib/ctypes /usr/local/lib/ocaml/unix.cmxa /usr/local/lib/ocaml/bigarray.cmxa /Users/mike/.opam/system/lib/ctypes/ctypes.cmxa /Users/mike/.opam/system/lib/ctypes/ctypes-foreign-base.cmxa /Users/mike/.opam/system/lib/ctypes/ctypes-foreign-unthreaded.cmxa test.ml
+ clang -arch x86_64 -c -o 'test.o' '/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlasmeaa663.s'
+ clang -arch x86_64 -c -o '/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlstartup56e173.o' '/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlstartup78207e.s'
+ cc -Wl,-no_compact_unwind -o 'test'   '-L/Users/mike/.opam/system/lib/ctypes' '-L/usr/local/lib/ocaml'  '/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlstartup56e173.o' '/usr/local/lib/ocaml/std_exit.o' 'test.o' '/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-unthreaded.a' '/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-base.a' '/Users/mike/.opam/system/lib/ctypes/ctypes.a' '/usr/local/lib/ocaml/bigarray.a' '/usr/local/lib/ocaml/unix.a' '/usr/local/lib/ocaml/stdlib.a' '-L/usr/local/Cellar/libffi/3.0.13/lib' '-lffi' '-lctypes-foreign-base_stubs' '-L/usr/local/Cellar/libffi/3.0.13/lib' '-lffi' '-lctypes_stubs' '-lbigarray' '-lunix' '/usr/local/lib/ocaml/libasmrun.a'

But when I use the -thread option:

$ ocamlfind ocamlopt -verbose -package ctypes,ctypes.foreign -linkpkg -thread -o test test.ml
Effective set of compiler predicates: pkg_unix,pkg_threads.posix,pkg_threads,pkg_bigarray,pkg_ctypes,pkg_ctypes.foreign-base,pkg_ctypes.foreign,autolink,mt,mt_posix,native
+ ocamlopt.opt -verbose -o test -thread -I /Users/mike/.opam/system/lib/ctypes /usr/local/lib/ocaml/unix.cmxa /usr/local/lib/ocaml/threads/threads.cmxa /usr/local/lib/ocaml/bigarray.cmxa /Users/mike/.opam/system/lib/ctypes/ctypes.cmxa /Users/mike/.opam/system/lib/ctypes/ctypes-foreign-base.cmxa /Users/mike/.opam/system/lib/ctypes/ctypes-foreign-threaded.cmxa test.ml
+ clang -arch x86_64 -c -o 'test.o' '/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlasmd75109.s'
File "test.ml", line 1:
Error: Files test.cmx
       and /Users/mike/.opam/system/lib/ctypes/ctypes-foreign-threaded.cmxa
       make inconsistent assumptions over implementation Foreign

I've deleted all the cmx/cmi/o files and rerun the above command, but I still get this error. Here I'm using ctypes 0.2.1 from opam on OSX, but this also fails for me with a ctypes 0.2.1 rpm I built in a CentOS 6.4 environment.

Am I doing something wrong here? Or is something wrong with the way ctypes is built and packaged?

Mike