Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7707529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:23:01+00:00 2026-06-01T00:23:01+00:00

Say, I have mylibrary.ml which provides wrappings to library.c and I want to bytecode-compile

  • 0

Say, I have mylibrary.ml which provides wrappings to library.c and I want to bytecode-compile and provide mylibrary.ml as a library for other ocaml code. Compiling this to bytecode (and I am not considering compiling ocaml to native code here) produces a number of files, and I am wondering if there is any reason to keep them all? Or to provide them all to other users of the library?

I (so far) understand that I need the bytecode library object mylibrary.cma so that I can use mylibrary in the ocaml toplevel as

ocaml mylibrary.cma

or that I can

#load "mylibrary.cma";;

from an ocaml script. Then also the compiled interface mylibrary.cmi, and the dllmylibrary.so (which contains the C parts of the code) are needed for the above to work. And the non compiled interface definition file mylibrary.mli is nice to keep for documentation purposes.

But is there any reason to retain also the mylibrary.cmo file, if I have the mylibrary.cma file? In what kind of case would someone like to have that, too?

EDIT: I mean, I need to construct the .cmo in the makefile and then use that to construct the .cma, but I was thinking to remove .cmo after this, to keep the directory marginally cleaner.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:23:03+00:00Added an answer on June 1, 2026 at 12:23 am

    So, apparently the purpose of different files are (when limiting this to bytecode compiler):

    mylibrary.mli – human readable interface definition (not strictly needed, compiler only needs .cmi)
    mylibrary.cmi – compiled interface, needed when compiling code calling mylibrary
    library.o – C object file
    dlllibrary.so – shared library object made of the .o
    dlllibrary.a – static library object made of the .o
    mylibrary.cmo – bytecode object compiled from mylibrary.ml
    mylibrary.cma – bytecode library

    Then, mylibrary.cma (with mylibrary.cmi and dlllibrary.so) are needed when loading mylibrary from the toplevel:

    #load "mylibrary.cma";;

    OR

    One could compile a bytecode program that dynamically links with mylibrary.cma (mylibrary.cmi and dlllibrary.so also needed):

    ocamlc mylibrary.cma <program>.ml

    OR

    dynamically linking with bytecode object, instead of the bytecode library (files needed: mylibrary.cmo, mylibrary.cmi, dlllibrary.so):

    ocamlc dlllibrary.so mylibrary.cmo <program>.ml

    (Note: then run the bytecode with: ocamlrun -I . <program>, assuming dlllibrary.so is in the current directory.)

    OR

    statically linking with objects (files needed: mylibrary.cmo, mylibrary.cmi liblibrary.a)

    ocamlc -custom liblibrary.a mylibrary.cmo <program>.ml

    OR

    statically linking with library objects (files needed: mylibrary.cma, mylibrary.cmi, liblibrary.a)

    ocamlc -custom -I . mylibrary.cma <program>.ml

    So depending on how one is going to use the library in the future, different files are needed. Except .mli is only needed for human readers, and the object file.o compiled from the C library is not needed (but would be needed when compiling to native code in some cases).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a package mylibrary. I want to make mylibrary.config available for import,
Lets say we have this route: routes.MapRoute( Library, Lib/{id}/{lang}, New With {.controller = MyLibrary,
Say I have a Telerik MVC Grid, AJAX bound and I want to put
Say I have classes class A{ //code for class A } class B{ //code
Say I have the following custom component: <s:Group xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark xmlns:mx=library://ns.adobe.com/flex/mx> <fx:Script> <![CDATA[ [Bindable]
I have a config file in my C# class library called MyLibrary.config, in vs
Say I have a byte array with 100,000 bytes in it. I want to
Let's say have a string... String myString = my*big*string*needs*parsing; All I want is to
Say I have a set of Strings that I want to be ordered by
Say have a linear model LM that I want a qq plot of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.