caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] libasmrun.a not compatible with dynamic linking on mac os x
@ 2012-07-16 15:05 Keyan
  2012-07-21  8:31 ` ygrek
  0 siblings, 1 reply; 4+ messages in thread
From: Keyan @ 2012-07-16 15:05 UTC (permalink / raw)
  To: caml-list

Hi,

i try to compile a dynamic library on mac os x, from ocaml-code using the following lines in my makefile;

camlopt -output-obj -o ocaml_controller.o -I /usr/local/lib/ocaml/site-lib/batteries ocaml_controller.ml 
ocamlc -o ocaml_interface.o -c ocaml_interface.c -I /usr/local/lib/ocaml/ 
libtool -static -a -o mylib.a /usr/local/lib/ocaml/libasmrun.a ocaml_controller.o ocaml_interface.o
g++ -o Controller.o -c Controller.cpp 
g++ -v -dynamiclib -o libController.dylib Controller.o mylib.a

The problem occurs at the last line, i.e. during linking of the dynamic lib.

Undefined symbols for architecture x86_64:
  "_caml_code_area_start", referenced from:
      _segv_handler in output.a(signals_asm.o)
      _caml_code_checksum in output.a(intern.o)
      _intern_rec in output.a(intern.o)
      _extern_rec in output.a(extern.o)
  "_caml_code_area_end", referenced from:
      _segv_handler in output.a(signals_asm.o)
      _caml_code_checksum in output.a(intern.o)
      _intern_rec in output.a(intern.o)
      _extern_rec in output.a(extern.o)
  "_caml_atom_table", referenced from:
      _caml_alloc in output.a(alloc.o)
      _caml_alloc_dummy_float in output.a(alloc.o)
      _caml_alloc_dummy in output.a(alloc.o)
      _caml_alloc_array in output.a(alloc.o)
      _caml_copy_string_array in output.a(alloc.o)
      _intern_alloc in output.a(intern.o)
      _intern_rec in output.a(intern.o)
      ...
ld: symbol(s) not found for architecture x86_64

libasmrun contains the symbols:

> nm /usr/local/lib/ocaml/libasmrun.a | grep _caml_code_area_start
0000000000000008 C _caml_code_area_start
                 U _caml_code_area_start
                 U _caml_code_area_start
                 U _caml_code_area_start

The problem only occurs while linking a dymamiclib, _not_ during a static lib, or an executable, with a c++ main. It seems that the libasmrun.a is not compatible with dynamic linking on mac os x.

Any help is very welcome!

Cheers,
Keyan



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

* Re: [Caml-list] libasmrun.a not compatible with dynamic linking on mac os x
  2012-07-16 15:05 [Caml-list] libasmrun.a not compatible with dynamic linking on mac os x Keyan
@ 2012-07-21  8:31 ` ygrek
  2012-07-21 17:16   ` Keyan
  0 siblings, 1 reply; 4+ messages in thread
From: ygrek @ 2012-07-21  8:31 UTC (permalink / raw)
  To: caml-list

On Mon, 16 Jul 2012 17:05:53 +0200
Keyan <ml@pulsschlag.net> wrote:

> Hi,
> 
> i try to compile a dynamic library on mac os x, from ocaml-code using the following lines in my makefile;
> 
> camlopt -output-obj -o ocaml_controller.o -I /usr/local/lib/ocaml/site-lib/batteries ocaml_controller.ml 
> ocamlc -o ocaml_interface.o -c ocaml_interface.c -I /usr/local/lib/ocaml/ 
> libtool -static -a -o mylib.a /usr/local/lib/ocaml/libasmrun.a ocaml_controller.o ocaml_interface.o
> g++ -o Controller.o -c Controller.cpp 
> g++ -v -dynamiclib -o libController.dylib Controller.o mylib.a

I couldn't fully reproduce these steps (on linux) because libtool doesn't want to accept such command line.
But still what occurs to me - you probably shouldn't use "ocaml_controller.o" as -output-obj target, because
the file with such name is generated as a .cmx companion. Name it smth like ocaml_controller_obj.o.
I've got ocamlopt errors otherwise. Does it help?

-- 
 ygrek
 http://ygrek.org.ua

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

* Re: [Caml-list] libasmrun.a not compatible with dynamic linking on mac os x
  2012-07-21  8:31 ` ygrek
@ 2012-07-21 17:16   ` Keyan
  2012-07-24 11:34     ` Damien Doligez
  0 siblings, 1 reply; 4+ messages in thread
From: Keyan @ 2012-07-21 17:16 UTC (permalink / raw)
  To: ygrek; +Cc: caml-list

Hi,

thanks for trying. I just recently solved this issue by compiling the code differently:

ocamlopt -o mylib.so ocaml_source.ml -ccopt my_c_source.c -ccopt -shared 
g++ -dynamiclib -o myfinallib.dylib -L/usr/local/lib/ocaml/ -lasmrun -lnums -ldl -Wl,-search_paths_first -Wl,-headerpad_max_install_names -fPIC Controller.o mylib.so 

I haven't even checked yet, if all the options are really required, i.e. -fPIC, and both -Wl, options.

Best,
Keyan

On 21 Jul 2012, at 10:31, ygrek wrote:

> On Mon, 16 Jul 2012 17:05:53 +0200
> Keyan <ml@pulsschlag.net> wrote:
> 
>> Hi,
>> 
>> i try to compile a dynamic library on mac os x, from ocaml-code using the following lines in my makefile;
>> 
>> camlopt -output-obj -o ocaml_controller.o -I /usr/local/lib/ocaml/site-lib/batteries ocaml_controller.ml 
>> ocamlc -o ocaml_interface.o -c ocaml_interface.c -I /usr/local/lib/ocaml/ 
>> libtool -static -a -o mylib.a /usr/local/lib/ocaml/libasmrun.a ocaml_controller.o ocaml_interface.o
>> g++ -o Controller.o -c Controller.cpp 
>> g++ -v -dynamiclib -o libController.dylib Controller.o mylib.a
> 
> I couldn't fully reproduce these steps (on linux) because libtool doesn't want to accept such command line.
> But still what occurs to me - you probably shouldn't use "ocaml_controller.o" as -output-obj target, because
> the file with such name is generated as a .cmx companion. Name it smth like ocaml_controller_obj.o.
> I've got ocamlopt errors otherwise. Does it help?
> 
> -- 
> ygrek
> http://ygrek.org.ua
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 


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

* Re: [Caml-list] libasmrun.a not compatible with dynamic linking on mac os x
  2012-07-21 17:16   ` Keyan
@ 2012-07-24 11:34     ` Damien Doligez
  0 siblings, 0 replies; 4+ messages in thread
From: Damien Doligez @ 2012-07-24 11:34 UTC (permalink / raw)
  To: caml users

On 2012-07-21, at 19:16, Keyan wrote:

> thanks for trying. I just recently solved this issue by compiling the code differently:
> 
> ocamlopt -o mylib.so ocaml_source.ml -ccopt my_c_source.c -ccopt -shared 
> g++ -dynamiclib -o myfinallib.dylib -L/usr/local/lib/ocaml/ -lasmrun -lnums -ldl -Wl,-search_paths_first -Wl,-headerpad_max_install_names -fPIC Controller.o mylib.so 

See also the simple example I've uploaded here:
  http://caml.inria.fr/mantis/view.php?id=5693

-- Damien


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

end of thread, other threads:[~2012-07-24 11:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-16 15:05 [Caml-list] libasmrun.a not compatible with dynamic linking on mac os x Keyan
2012-07-21  8:31 ` ygrek
2012-07-21 17:16   ` Keyan
2012-07-24 11:34     ` Damien Doligez

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).