In Opam how do I tell which package owns a given file? - ocaml

In Opam how do I tell which package owns a given file under ${OPAMROOT}/system? If there is no direct mean to achieve this, is it possible to list files owned by a given package?

The following command lists all packages and the files included in them - one can dump the output to a file to search it.
opam list -s | xargs -t -n 1 opam show --list-files > files.txt 2>&1
(tested with opam 2.1)

There is no such facility, as opam allows packages to install their files virtually everywhere. But in general structure is quite simple and most packages respect it:
Each installed package has its own subfolder in lib, etc, doc and share.
For each package opam creates an entry install/<package-name>.install that may contain files that this package installed, if special facilities, provided by opam, were used in the installation process.
binaries are put into bin or sbin without further subdivision.

Related

I can't manage to install any ocaml modules

I'm trying to install a linear programming solver in ocaml, but i can't get any modules to work
I found this : https://github.com/Gbury/Ocaml-simplex
and this : https://github.com/smimram/ocaml-glpk
I'm just following what's written to do (make / make install) but evertytime after the installation, when i try to open Glpk or open Simplex it's not working. In fact even the examples files included are not working
I don't know if I'm doing something wrong or if those modules are just not working
Please help me I'm becoming mad.
Additional information on my problem:
I'm on Debian, the last version I guess. To install the modules, I downloaded the zip files, i installed the required modules, then unzipped, ./configure, make, make install, just what's written on GitHub.
But then when i open an example test files, which begins by open Glpk (the module I'm trying to install), when i try to compile i've an error :
open Glpk
^^^^
Error: Unbound module Glpk
I mean I've found 3 modules to make linear programming solver:
https://github.com/OCamlPro-Iguernlala/ocplib-simplex
https://github.com/Gbury/Ocaml-simplex
https://github.com/smimram/ocaml-glpk
And I can't get any of them to work.
From your description, your issue is not installing libraries but using them. Once you have installed a library, you still need to inform the compiler on where are the compiled interfaces files (.cmi) for this library, and which object files should be linked (aka .cm(x)o and .cm(x)a) .
It will be much easier to let a package manager (like opam) and a build tool (like dune) take care of those minutiæ.
For instance, with opam and dune, you can first install ocplib-simplex:
opam install simplex
Then building a executable from a main.ml file using this library can be done with a dune file
(executable (name main) (libraries ocplib-simplex) )
and a call to
dune build main.exe
I managed to get Glpk working in no time. I think you should learn a bit about OPAM, the OCaml Package Manager. Its purpose is exactly to make library installation as easy as possible. Here's a step-by-step:
Prerequisites
I'm going to assume you have OPAM installed. If this is not the case, you'll find the information you need here. The easiest way to get OPAM working is to execute the following in a shell:
sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh) && \
opam init && \
eval $(opam env)
Installing Glpk
First, I tried to install Glpk as is.
opam install glpk
This failed with following error:
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build glpk 0.1.8
└─
╶─ No changes have been performed
The packages you requested declare the following system dependencies. Please make sure they are installed before retrying:
libglpk-dev
This is because the OCaml library Glpk is actually a binding to a system library which needs to be installed separately. On Debian, you can use apt to do this.
sudo apt install libglpk-dev
Then I retried installing Glpk.
opam install glpk
It succeeded. Great.
Requiring Glpk
Now that the Glpk library is installed, you need to require it in order to make it available.
In a REPL
When using the OCaml toplevel, you need to use the following commands in order to require Glpk.
#use "topfind";;
#require "glpk";;
In a project
If you want to use libraries in a fully-fledged project (with multiple files, executables and whatnot), you should use a build system. The most popular OCaml build system today is Dune, which Octachron covered in his answer.
Further considerations
You should consider reading Real World OCaml, a great book that teaches from the ground up everything you need to know to build software with OCaml.

Loris package installing issue

I'm trying to install Loris package link which is a library also for Python (my language). I have installed the package through bash commands in my OSX 10.12 system following these steps:
cd to the directory containing the package's source code and type
./configure to configure the package for your system. If you're
using csh on an old version of System V, you might need to type
sh ./configure instead to prevent csh from trying to execute
configure itself.
Running `configure' takes awhile. While running, it prints some
messages telling which features it is checking for.
Type `make' to compile the package.
Optionally, type `make check' to run any self-tests that come with
the package.
Type `make install' to install the programs and any data files and
documentation.
You can remove the program binaries and object files from the
source code directory by typing make clean. To also remove the
files that configure created (so you can compile the package for
a different kind of computer), type make distclean. There is
also a make maintainer-clean target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
The problem is that when I run both python 2.7 IDLE and the Atom editor it says that the module named Loris was not found. By default, make install will install the package's files in
/usr/local/bin,/usr/local/man.
Is this the problem? How can I install properly this library?

iwlib.h: No such file or directory

This is the first time for me to use Linux and its development tools. When I was trying to build the project I have to read, I had an error:
/home/charlie/AODV/llf.c:36: error: iwlib.h: No such file or directory
I was building the project with Qt. Beforehand, I installed libnl by make and make install, but the problem was not resolved. I am wondering if I did not install libel correctly or there are something more I have to do.
Welcome to Linux development.
You need to install libiw and it's development header(s).
How to do this is distribution dependant. On my Debian (should be more or less the same on any Debian based distro like Ubuntu):
jbm#sumo:~$ apt-cache search libiw
libiw-dev - Wireless tools - development files
libiw30 - Wireless tools - library
libiw30 is the binary lib, and the *-dev package is for it's header file(s), plus sometimes some docs (man pages etc). So:
jbm#sumo:~$ sudo apt-get install libiw-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
[...]
The following additional packages will be installed:
libiw30
The following NEW packages will be installed:
libiw-dev libiw30
Note how installing the header(s) for a lib rightfully install the library as well.
After install:
jbm#sumo:~$ find /usr/include/ -name iwlib.h
/usr/include/iwlib.h
jbm#sumo:~$ find /usr/lib -name "libiw*"
/usr/lib/x86_64-linux-gnu/libiw.so
/usr/lib/x86_64-linux-gnu/libiw.a
Note that:
/usr/include is part of the standard search path for headers of your
gcc toolchain, so you don't need to add a peculiar -I (for "include")
option.
/usr/lib is the same for lib binaries, so no need any -l or
-L (for "link") option.
You need to say to the compiler where to look for the header file. Use the -Idir option with dir the directory where the header file is.

How to use ocamlbuild with OPAM in ocaml?

I wrote two libraries (Bson.ml and Mongo.ml) in ocaml.
I wish to enable it for opam.
In the instruction of opam, it says it needs make build and make install.
I am always using ocamlbuild and ocamlfind to build and install my library locally.
How can I produce a make file for opam?
Just do it the way other packages do it. For example the sequence package also uses vanilla ocamlbuild and ocamlfind. Here's the opam package description for it: https://github.com/OCamlPro/opam-repository/tree/master/packages/sequence.0.3.4 The opam file specifically.

Google protobuf in Linux

I'm working with protobuf and Linux. Where is its compiler protoc? I've downloaded the package from the main site, compiled and installed it successfully but I can't find protoc to build my own format file. Where is it?
UPDATE
Here is folder where I built protobuf:
aclocal.m4 depcomp Makefile.in
autogen.sh editors missing
CHANGES.txt examples protobuf-lite.pc
config.guess generate_descriptor_proto.sh protobuf-lite.pc.in
config.h gtest protobuf.pc
config.h.in install-sh protobuf.pc.in
config.log INSTALL.txt python
config.status java README.txt
config.sub libtool src
configure ltmain.sh stamp-h1
configure.ac m4 vsprojects
CONTRIBUTORS.txt Makefile
COPYING.txt Makefile.am
There isn't a binary file I need.
It's probably installed into /usr/local/bin
On Ubuntu at least, you can apt-get install protobuf-compiler instead.
From the INSTALL.txt:
Installation Names
By default, 'make install' will install the package's files in
'/usr/local/bin', '/usr/local/man', etc. You can specify an
installation prefix other than '/usr/local' by giving 'configure' the
option '--prefix=PATH'.
First, you need to compile you source code from protobuff (in the root folder):
./configure
make
make check
make install
Second:
echo "/usr/local/lib">>/etc/ld.so.conf
echo "/usr/lib">>/etc/ld.so.conf
ldconfig
Third:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
Read README.txt in root folder for more info.
Also, if you are in fact on Ubuntu, then you can also fetch the source package from Debian unstable and rebuild them locally if you want packages that are more current than the last cutoff (which for Ubuntu 9.10 was some time late last summer). That way you end up with .deb packages and you preserve a normal upgrade path (rather than littering /usr/local with one-off installs).
You can find protoc in the path which you set ./configure --prefix=you_path.
When you make install successful, it will general bin, include and lib in that path.
Actually you don't need to know it's place.
All you want is to open terminal where your proto file is located and write at terminal
protoc -I=. --cpp_out=. filename.proto
follow this link for documentation