Skip to content

Teach ocamlbuild to create shared libraries using -output-obj #6733

@vicuna

Description

@vicuna

Original bug ID: 6733
Reporter: @whitequark
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2017-02-16T14:15:07Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 4.02.2+dev / +rc1
Category: -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues
Tags: patch
Related to: #6693 #6797 #6845 #6918 #6927
Monitored by: @hcarty

Bug description

Currently I am using the following code (parts of which are pulled into myocamlbuild, not being accessible from ocamlbuild library):

  let native_link_gen linker =
    Ocaml_compiler.link_gen "cmx" "cmxa"
      !Options.ext_lib [!Options.ext_obj; "cmi"] linker
  in
  let native_output_obj x = native_link_gen Ocaml_compiler.ocamlopt_link_prog
    (fun tags -> tags++"ocaml"++"link"++"native"++"output_obj"++"output_so") x
  in
  flag ["ocaml"; "link"; "output_so"] & S[A"-cclib"; A"-shared"];
  flag ["ocaml"; "link"; "output_obj"; "debug"] & A"-g";
  rule "ocaml: cmx & o -> native.(so|dll|dylib)"
    ~prod:("%.native"-.-(!Options.ext_dll))
    ~deps:["%.cmx"; "%.o"]
    (native_output_obj "%.cmx" ("%.native"-.-(!Options.ext_dll)));

Then, I just do ocamlbuild foo.native.so. It works flawlessly.

Possibly it is also useful to provide foo.byte.so.

File attachments

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions