I come here with a better understanding of my issue but still no way to solve it after reading forums, documentations and try different options (even the minimal command line example).
Context:
I’m using this library for my internship, ocaml_mammut. This is a C++ binding to this library, mammut.
The dune file for the ocaml-mammut
is:
(library
(name mammut)
(public_name mammut)
(flags (:standard -w -49 -linkall ))
(modules mammut)
(libraries ctypes.stubs mammut.generated threads)
(c_library_flags -lstdc++)
)
The mammut.generated
is here to compile the mammut c++
library and generate the c++ stubs. Its dune is this one (a bit long sorry):
(library
(name mammut_generated)
(public_name mammut.generated)
(wrapped false)
(modules mammut_generated)
(libraries ctypes.stubs mammut_stubs_description)
(foreign_stubs
(language c)
(names mammut_stubs)
(include_dirs ../../vendor/mammut/include))
(foreign_archives raplcap-msr mammut usb-1.0 smartgauge)
(c_library_flags -lstdc++)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(rule
(targets libraplcap-msr.a dllraplcap-msr%{ext_dll})
(deps (source_tree ../../vendor))
(action (progn
(chdir ../../vendor/raplcap (progn
(bash
"cmake -B_build/shared -DBUILD_SHARED_LIBS=ON .")
(bash
"cmake --build _build/shared")))
(bash
"cp ../../vendor/raplcap/_build/shared/msr/libraplcap-msr.so dllraplcap-msr.so")
(chdir ../../vendor/raplcap (progn
(bash
"cmake -B_build/static .")
(bash
"cmake --build _build/static")))
(bash
"cp ../../vendor/raplcap/_build/static/msr/libraplcap-msr.a .")
)))
; The vendored libmammut.
(data_only_dirs vendor)
(rule
(targets libmammut.a dllmammut%{ext_dll} libusb-1.0.a dllusb-1.0%{ext_dll} libsmartgauge.a dllsmartgauge%{ext_dll})
(deps (source_tree ../../vendor))
(action (progn
(chdir ../../vendor/mammut (progn
(bash
"cmake .")
(bash
"make")))
(bash
"cp ../../vendor/mammut/src/libmammut_static.a libmammut.a")
(bash
"cp ../../vendor/mammut/src/libmammut.so dllmammut.so")
(bash
"cp ../../vendor/mammut/src/external/libusb-1.0.9/libusb/.libs/libusb-1.0.a .")
(bash
"cp ../../vendor/mammut/src/external/libusb-1.0.9/libusb/.libs/libusb-1.0.so dllusb-1.0.so")
(bash
"cp ../../vendor/mammut/src/external/odroid-smartpower-linux/libsmartgauge.a .")
(bash
"cp ../../vendor/mammut/src/external/odroid-smartpower-linux/libsmartgauge.so dllsmartgauge.so")
)))
;;;;;;;;;;;;;;;;;;
; Type bindings.
(library
(name generate_types)
(public_name mammut.generated_type_descriptions)
(modules generate_types)
(libraries ctypes.stubs))
(executable
(name generate_types_start)
(modules generate_types_start)
(libraries ctypes.stubs generate_types))
(rule
(with-stdout-to mammut_generated.types.c
(run ./generate_types_start.exe)))
; Based partially on
; https://github.com/avsm/ocaml-yaml/blob/master/types/stubgen/jbuild#L20
(rule
(targets mammut_types.exe)
(deps (:c mammut_generated.types.c))
(action (bash "\
%{cc} %{c} \
-I '%{lib:ctypes:.}' \
-I %{ocaml_where} \
-I ../../vendor/mammut/include -o %{targets}")))
(rule
(with-stdout-to mammut_types.ml
(run ./mammut_types.exe)))
; Function bindings.
(library
(name mammut_stubs_description)
(public_name mammut.generated_function_descriptions)
(flags (:standard -w -9-16-27))
(wrapped false)
(modules mammut_types mammut_stubs_description)
(libraries ctypes.stubs generate_types))
(executable
(name generate_c_functions)
(modules generate_c_functions)
(libraries ctypes.stubs mammut_stubs_description))
(executable
(name generate_ml_functions)
(modules generate_ml_functions)
(libraries ctypes.stubs mammut_stubs_description))
(rule
(with-stdout-to mammut_generated.ml
(run ./generate_ml_functions.exe)))
(rule
(with-stdout-to mammut_stubs.c
(run ./generate_c_functions.exe)))
Attempts:
In the current state of ocaml-mammut
, when you use it into another project, you have to specify the flags with (flags (-cclib -lraplcap-msr -cclib -lsmartgauge -cclib -lusb-1.0 -cclib -lmammut))
in the project itself. However, according to the manual and this discussion I had with @ivg, if I transform the ocaml-mammut
dune in this way:
(library
(name mammut)
(public_name mammut)
(flags (:standard -w -49 -linkall
-cclib generated
-cclib -lraplcap-msr
-cclib -lsmartgauge
-cclib -lusb-1.0
-cclib -lmammut ))
(modules mammut)
(libraries ctypes.stubs mammut.generated threads)
(c_library_flags -lstdc++)
)
I’m not supposed to have to write the (flags ...)
stanza in other projects any more because it should be a standalone library.
Issue:
When I use the previous dune, it compiles, I get the c++ .a
libraries at the right place. However, when I reach the link point, it fails with:
ocamlopt src/mammut.cmxs (exit 2)
(cd _build/default && /home/etienne/.opam/default/bin/ocamlopt.opt -w
@1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence
-strict-formats -short-paths -keep-locs -w -49 -linkall -cclib -lstdc++
-cclib -lraplcap-msr
-cclib -lsmartgauge -cclib -lusb-1.0 -cclib
-lmammut -g -shared -linkall -I src -o src/mammut.cmxs src/mammut.cmxa)
/usr/bin/ld: cannot find -lraplcap-msr
/usr/bin/ld: cannot find -lsmartgauge
/usr/bin/ld: cannot find -lusb-1.0
/usr/bin/ld: cannot find -lraplcap-msr
/usr/bin/ld: cannot find -lsmartgauge
/usr/bin/ld: cannot find -lusb-1.0
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking (exit code 1)
I don’t understand why dune
can’t find the .a
and add them in the cmxa
whereas there are in the _build
repository.