Version française
Home     About     Download     Resources     Contact us    
Browse thread
Dynamic libs w/ Ocaml + C code under Mac OS X
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Stanley <jstanley@g...>
Subject: Dynamic libs w/ Ocaml + C code under Mac OS X
Hi folks,

mfp from #ocaml suggested I send this off to the mailing list to see  
if anyone knows the answer.

The short question is: can I currently generate a shared library  
containing natively-compiled ocaml code together with arbitrary C code  
under Mac OS X?  Alain Frisch's natdynlink info page at http://alain.frisch.fr/natdynlink.html 
  seems to indicate that I can, but I'm not currently having much luck.

To wit, should I be doing something other than:

$ gcc -c wrapper.c
$ ocamlopt -dlcode -c simple.ml
...
$ ocamlopt -shared -o test simple.cmx wrapper.o

or perhaps just ocamlopt -shared -o test simple.ml wrapper.c?

The immediate problem is that this seems to be passing the wrong  
arguments to ld:

+ ld -bundle -flat_namespace -undefined suppress -read_only_relocs  
suppress -o 'test'  -I'/Users/jstanley/hbin/lib/ocaml' '-L/Users/ 
jstanley/hbin/lib/ocaml' 'test.startup.o' 'simple.o' 'wrapper.o'

(I'd expect to see gcc -dynamiclib (instead of bundle) here if Mac OS  
X is supported, and without the -I switch).

However, even attempting to use what I'd consider to be the "correct"  
linker invocation, I'm getting errors of the form:

ld: atom sorting error for _caml_shared_startup__code_begin and  
_caml_shared_startup__code_end in test.startup.o
ld: atom sorting error for _caml_shared_startup__code_begin and  
_caml_shared_startup__code_end in test.startup.o
ld: atom sorting error for _caml_shared_startup__code_begin and  
_caml_shared_startup__code_end in test.startup.o
ld: atom sorting error for _caml_shared_startup__code_begin and  
_caml_shared_startup__code_end in test.startup.o
ld: warning codegen in _camlSimple__f_58 (offset 0x00000008) prevents  
image from loading in dyld shared cache
ld: warning codegen in _camlSimple__entry (offset 0x00000004) prevents  
image from loading in dyld shared cache
ld: warning codegen in _camlSimple__entry (offset 0x00000009) prevents  
image from loading in dyld shared cache
ld: warning codegen in _camlSimple__entry (offset 0x0000000F) prevents  
image from loading in dyld shared cache
ld: warning codegen in _camlSimple__entry (offset 0x00000014) prevents  
image from loading in dyld shared cache
ld: warning codegen in _camlSimple__entry (offset 0x0000001E) prevents  
image from loading in dyld shared cache
ld: absolute addressing (perhaps -mdynamic-no-pic) used in  
_camlSimple__f_58 from simple.o not allowed in slidable image
collect2: ld returned 1 exit status

which lead me to believe that simple.o is not correctly being  
generated with position independence.

Thanks for any help you may be able to provide.

--
Joel Stanley