4

My project is using ctypes library and markup library. When compile, it gives following complain:

Error: Files /Users/Young/.opam/4.02.1/lib/markup/markup.cmxa
       and /Users/Young/.opam/4.02.1/lib/ctypes/ctypes.cmxa
       both define a module named Common

Obviously, both libraries expose same module name. How to fix it? Any help will be appreciated. Thanks.

Update: Also I don't quite understand why there'll be such a conflict. To my understanding, even if both libraries expose the same module Common, they will appear as Ctypes.Common vs Markup.Common. There's should be no conflict?

Oliver Young
  • 578
  • 1
  • 4
  • 12

1 Answers1

4

In general, you can't solve this without modifying an upstream, so in case of such errors, you need to ask the library maintainers to rename corresponding modules.

In your case, using a newer version of ctypes library should help, as on mine machine the ctypes (version 0.11.2) library no longer defines the Common module.

Update: Also I don't quite understand why there'll be such a conflict. To my understanding, even if both libraries expose the same module Common, they will appear as Ctypes.Common vs Markup.Common. There's should be no conflict?

Your understanding is more or less correct. There are few details however, a library is a collection of compilation units, each compilation unit is a collection of modules. Compilation units basically maps to files, e.g., if you have file common.ml, then the compilation unit would have the common name. Libraries and compilation units live in a flat namespace, modules in general leave in a hierarchical namespace. That means, that filenames from which libraries are built must have different names, that's why if you will look at the latest codebase, you will notice that all filenames are prefixed with ctypes_. There is a partial solution, to mitigate this namespace problem one can use packed modules, in that case only one module (usually with the same name as the library).

ivg
  • 34,431
  • 2
  • 35
  • 63
  • Thanks for the comments. Unfortunately, I use async_ssl which requires the version of ctypes <=0.4.0 – Oliver Young Feb 20 '17 at 19:13
  • You're using an old async_ssl, the newer one (e.g., async_ssl.113.+ requires ctypes >= 0.6). As far as I know, the latest async (start from the 113 version) requires OCaml 4.02.3 or greater. – ivg Feb 20 '17 at 20:00
  • Thanks. Will look into that. BTW, may I know why would we have such a conflict between modules? To my understanding, even if both libraries expose the same module Common, they will appear as Ctypes.Common vs Markup.Common. – Oliver Young Feb 20 '17 at 20:09
  • Libraries are not adding a namespace basically if both libraries are exposing module `M`, then it will be available under the `M` name without any prefixes. A library is just an archive. I've updated the answer, to make it more clear. – ivg Feb 20 '17 at 20:23
  • Thanks for the detailed answer. That clears my doubts. Very useful – Oliver Young Feb 20 '17 at 23:32