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 6995089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:58:35+00:00 2026-05-27T19:58:35+00:00

I have a file Tools.ml which contains some common utility functions I write myself.

  • 0

I have a file Tools.ml which contains some common utility functions I write myself. Under .../Code/ I have several folders which each contains a project. My question is where I should place this Tools.ml such that all the folders and files under .../Code/ could share this module by Open Tools.

Hope my question is clear… Does anyone have a good solution?

Edit1: Following @gasche’s answer, I have written tools.ml as follows:

module Tools =
  struct
    let a_function = ...
    ...
  end

Then I compiled it, and done ocamlfind install tools META tools.cmo tools.cmx tools.ml as suggested, which looks going well. Then I have written test.ml as follows:

open Tools

let f = Tools.a_function

then I compiled it with ocamlc test.ml -o test, then I got an error:

File "test.ml", line 1, characters 0-1:
Error: Error while linking test.cmo:
Reference to undefined global `Tools'

Could anyone tell me what happened?

  • 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-05-27T19:58:36+00:00Added an answer on May 27, 2026 at 7:58 pm

    You could package it as an independent library, install it with other OCaml libraries, and access to it, from your project, as a library.

    A very simple way to do this is to write a META file for ocamlfind. Create a directory somewhere you’re comfortable to hold you “personal library” project. Suppose you have tools.ml and tools.mli, and your code depends on some findlib package (eg. unix and bigarray). You META would look like this:

    name="tools"
    description="personal collection of utilities"
    version="0.1"
    requires="unix,bigarray"
    archive(byte)="tools.cmo"
    archive(native)="tools.cmx"
    

    Once you have written this META file, it is easy to ask ocamlfind to “install” the library (and remove it if you want to), and use it in your other projects. To install, the syntax is ocamlfind install <name> <meta-file> <file1> <file2> ... where <file1>, <file2>.. are the file you wish to see included in the installation directory. You must at least have tools.cmi tools.cmo (and tools.o and tools.cmx for native compilation), but it is good practice to also have tools.mli for example (and, if you want to provide the code, tools.ml).

    ocamlfind install tools META tools.cmi tools.cmo tools.o tools.cmx tools.mli
    

    (Of course tools.cmo etc. have to exist, that is you must install after you have compiled your package. If you have used ocamlbuild, they are likely to be in a _build subdirectory, so ocamlfind install ... _build/tools.cmo ....)

    From your numerous projects, you can use your library easily, either using the ocamlfind toold directly if this is what you already do to compile your programs

    ocamlfind ocamlc -package tools ....
    

    or through the facilities provided by ocamlbuild for example, adding package(tools) to your tags.

    To reinstall your library if you made a change to it and want it accessible from your projects

    ocamlfind remove tools
    ocamlfind install tools META ...
    

    You could also handle all this through oasis, which is a layer on top of ocamlfind/ocamlbuild to automate this process. I’m not familiar enough with oasis to give such examples off the top of my head, but it should be equally simple for such a restricted case (one-file library), and scale better if you wish later to extend your library (eg. it can also handle documentation generation, pre-compilation configuration…).

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

Sidebar

Related Questions

I have a text file which contains some numerals, for example, There are 60
I have a C file which contains lots of code comments, how I can
Looking for suggestions on file system management tools. We have several terabytes of images,
I have a svg file which contains complex paths with bezier curves in it.
I have a text file which was created using some Microsoft reporting tool. The
Just a quick question. I have a system which contains some silverlight elements to
I have some JavaScript, which is generated by PHP code, using a template. The
We have a tool that generates source files, and each generated file has several
Say I have file A, in middle of which have a tag string #INSERT_HERE#.
I have a variable in code that can have file path or url as

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.