Open mseri opened 2 years ago
The latter problem should be because it is creating dummies and configuration files, and you do not appear to have permission to edit files there.
The former should be expected (I believe). It is my understanding that even standard libraries such as GMP and MPFR cannot find things there unless some of your environment variables to point there.
So now the version of the library use pkg-config
, which allow it to be compiled in particular on macosx. @mseri can you test the new master version? It should land in opam soon, https://github.com/ocaml/opam-repository/pull/23244
It still fails to me, but now it is because the ocaml code is not using pkg-config:
mkdir -p "/Users/mseri/code/ocaml/ocaml-flint/_build/.sandbox/5b075a58457560a58a9094a9156149aa/default/flint/flint/flint2/../prefix/include/flint"
cp aprcl.h ulong_extras.h long_extras.h perm.h fmpz.h fmpz_vec.h fmpz_poly.h fmpq_poly.h fmpz_mat.h fmpz_lll.h mpfr_vec.h mpfr_mat.h mpf_vec.h mpf_mat.h nmod.h nmod_vec.h nmod_poly.h nmod_poly_factor.h arith.h mpn_extras.h nmod_mat.h fmpq.h fmpq_vec.h fmpq_mat.h padic.h fmpz_poly_q.h fmpz_poly_mat.h nmod_poly_mat.h fmpz_mod_poly.h fmpz_mod_poly_factor.h fmpz_factor.h fmpz_poly_factor.h fft.h qsieve.h double_extras.h d_vec.h d_mat.h padic_poly.h padic_mat.h qadic.h fq.h fq_vec.h fq_mat.h fq_poly.h fq_poly_factor.h fq_embed.h fq_nmod.h fq_nmod_vec.h fq_nmod_mat.h fq_nmod_poly.h fq_nmod_poly_factor.h fq_nmod_embed.h fq_zech.h fq_zech_vec.h fq_zech_mat.h fq_zech_poly.h fq_zech_poly_factor.h fq_zech_embed.h fmpz_mod_mat.h mpoly.h fmpz_mpoly.h fmpq_mpoly.h nmod_mpoly.h fq_nmod_mpoly.h thread_pool.h thread_support.h fmpz_mod.h fmpz_mod_vec.h fmpz_mod_mpoly.h fmpz_mod_mpoly_factor.h n_poly.h fmpz_mpoly_factor.h fmpq_mpoly_factor.h nmod_mpoly_factor.h fq_nmod_mpoly_factor.h fq_zech_mpoly.h fq_zech_mpoly_factor.h fq_default.h fq_default_poly.h fq_default_poly_factor.h fq_default_mat.h NTL-interface.h flint.h longlong.h flint-config.h gmpcompat.h fft_tuning.h fmpz-conversions.h profiler.h templates.h exception.h hashmap.h fq_vec_templates.h fq_mat_templates.h fq_poly_templates.h fq_poly_factor_templates.h fq_embed_templates.h fq_templates.h "/Users/mseri/code/ocaml/ocaml-flint/_build/.sandbox/5b075a58457560a58a9094a9156149aa/default/flint/flint/flint2/../prefix/include/flint"
mkdir -p "/Users/mseri/code/ocaml/ocaml-flint/_build/.sandbox/5b075a58457560a58a9094a9156149aa/default/flint/flint/flint2/../prefix/include/flint/flintxx"
cp flintxx/*.h "/Users/mseri/code/ocaml/ocaml-flint/_build/.sandbox/5b075a58457560a58a9094a9156149aa/default/flint/flint/flint2/../prefix/include/flint/flintxx"
cp *xx.h "/Users/mseri/code/ocaml/ocaml-flint/_build/.sandbox/5b075a58457560a58a9094a9156149aa/default/flint/flint/flint2/../prefix/include/flint"
File "flint/dune", line 8, characters 9-26:
8 | (names ocaml_flint_utils)
^^^^^^^^^^^^^^^^^
(cd _build/default/flint && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 -fdiagnostics-color=always -g -I /Users/mseri/.opam/5.0.0/lib/ocaml -I /Users/mseri/.opam/5.0.0/lib/bigarray-compat -I /Users/mseri/.opam/5.0.0/lib/bytes -I /Users/mseri/.opam/5.0.0/lib/ctypes -I /Users/mseri/.opam/5.0.0/lib/integers -I /Users/mseri/.opam/5.0.0/lib/ocaml/str -I /Users/mseri/.opam/5.0.0/lib/ocaml/threads -I /Users/mseri/.opam/5.0.0/lib/ocaml/unix -I /Users/mseri/.opam/5.0.0/lib/stdlib-shims -I /Users/mseri/.opam/5.0.0/lib/zarith -I flint -I /Users/mseri/.opam/5.0.0/lib/zarith -o ocaml_flint_utils.o -c ocaml_flint_utils.c)
In file included from ocaml_flint_utils.c:1:
./flint/fmpz.h:27:10: fatal error: 'gmp.h' file not found
#include <gmp.h>
^~~~~~~
1 error generated.
File "flint/_unknown_", line 1, characters 0-0:
(cd _build/default && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 -fdiagnostics-color=always -g -I/Users/mseri/code/ocaml/ocaml-flint/_build/default/flint/flint -I/Users/mseri/code/ocaml/ocaml-flint/_build/default/flint/. -Werror=implicit-function-declaration -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 -fdiagnostics-color=always -g -I /Users/mseri/.opam/5.0.0/lib/ocaml -I /Users/mseri/.opam/5.0.0/lib/ctypes /Users/mseri/code/ocaml/ocaml-flint/_build/default/flint/flint__c_cout_generated_types.c -o /Users/mseri/code/ocaml/ocaml-flint/_build/default/flint/flint__c_cout_generated_types.exe)
In file included from /Users/mseri/code/ocaml/ocaml-flint/_build/default/flint/flint__c_cout_generated_types.c:1:
/Users/mseri/code/ocaml/ocaml-flint/_build/default/flint/./flint/fmpz.h:27:10: fatal error: 'gmp.h' file not found
#include <gmp.h>
^~~~~~~
1 error generated.
I would suggest to do that via dune-configurator, akin to what I did here: https://github.com/thvnx/mlmpfr/pull/27 (you just need a small modification of that code, I can send a PR next week if you want)
My bad, I pushed the tag 0.2.1
with dune-release but forgot to push the branch. main
is updated now. In particular, https://github.com/bobot/ocaml-flint/commit/221ac6e6eceead2ebf6e5f2968dc570d6ee19cde
There is only one error left now:
Running[1]: (cd _build/default/flint && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 -fdiagnostics-color=always -g -I /Users/mseri/.opam/5.0.0/lib/ocaml -I /Users/mseri/.opam/5.0.0/lib/bigarray-compat -I /Users/mseri/.opam/5.0.0/lib/bytes -I /Users/mseri/.opam/5.0.0/lib/ctypes -I /Users/mseri/.opam/5.0.0/lib/integers -I /Users/mseri/.opam/5.0.0/lib/ocaml/str -I /Users/mseri/.opam/5.0.0/lib/ocaml/threads -I /Users/mseri/.opam/5.0.0/lib/ocaml/unix -I /Users/mseri/.opam/5.0.0/lib/stdlib-shims -I /Users/mseri/.opam/5.0.0/lib/zarith -I flint -I /Users/mseri/.opam/5.0.0/lib/zarith -o ocaml_flint_utils.o -c ocaml_flint_utils.c)
File "flint/dune", line 8, characters 9-26:
8 | (names ocaml_flint_utils)
^^^^^^^^^^^^^^^^^
Command [1] exited with code 1:
$ (cd _build/default/flint && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 -fdiagnostics-color=always -g -I /Users/mseri/.opam/5.0.0/lib/ocaml -I /Users/mseri/.opam/5.0.0/lib/bigarray-compat -I /Users/mseri/.opam/5.0.0/lib/bytes -I /Users/mseri/.opam/5.0.0/lib/ctypes -I /Users/mseri/.opam/5.0.0/lib/integers -I /Users/mseri/.opam/5.0.0/lib/ocaml/str -I /Users/mseri/.opam/5.0.0/lib/ocaml/threads -I /Users/mseri/.opam/5.0.0/lib/ocaml/unix -I /Users/mseri/.opam/5.0.0/lib/stdlib-shims -I /Users/mseri/.opam/5.0.0/lib/zarith -I flint -I /Users/mseri/.opam/5.0.0/lib/zarith -o ocaml_flint_utils.o -c ocaml_flint_utils.c)
In file included from ocaml_flint_utils.c:1:
./flint/fmpz.h:27:10: fatal error: 'gmp.h' file not found
#include <gmp.h>
^~~~~~~
1 error generated.
I think the flags need to be added also to https://github.com/bobot/ocaml-flint/blob/4c3e97cf77adcb0183057735ed277f3ac1b0461f/flint/dune#L6
I tried
diff --git a/flint/dune b/flint/dune
index 06a7e04..969ca24 100644
--- a/flint/dune
+++ b/flint/dune
@@ -6,6 +6,9 @@
(foreign_stubs
(language c)
(names ocaml_flint_utils)
+ (flags
+ (:include ../configure/c_flags.sexp)
+ :standard)
(include_dirs
flint
(lib zarith)))
on the fly but it then fails at the final linking stage
Running[5]: (cd _build/default && /Users/mseri/.opam/5.0.0/bin/ocamlopt.opt -w -9-27 -g -shared -linkall -I flint -I flint/flint -o flint/flint.cmxs flint/flint.cmxa)
File "flint/dune", line 1, characters 0-993:
1 | (library
2 | (name flint)
3 | (public_name flint)
....
37 | (functor Function_description))
38 | (generated_types Types_generated)
39 | (generated_entry_point C)))
Command [5] exited with code 2:
$ (cd _build/default && /Users/mseri/.opam/5.0.0/bin/ocamlopt.opt -w -9-27 -g -shared -linkall -I flint -I flint/flint -o flint/flint.cmxs flint/flint.cmxa)
ld: library not found for -lgmp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking (exit code 1)
@bobot I think I figured it out. With the following the libraries work fine and passes the tests:
diff --git a/arb/dune b/arb/dune
index 68925d4..ba0769d 100644
--- a/arb/dune
+++ b/arb/dune
@@ -5,7 +5,10 @@
(foreign_archives arb)
(foreign_stubs
(language c)
- (names ocaml_acb_utils))
+ (names ocaml_acb_utils)
+ (flags
+ (:include ../configure/c_flags.sexp)
+ :standard))
(libraries zarith flint threads)
(flags -w -9-27)
(ctypes
@@ -18,7 +21,9 @@
"-Werror=implicit-function-declaration"
(:include ../configure/c_flags.sexp)
:standard)
- (c_library_flags "-lgmp -lmpfr")))
+ (c_library_flags
+ (:include ../configure/libs.sexp)
+ "-lgmp -lmpfr")))
(deps arb.h acb.h)
(headers
(include "acb.h" "string.h"))
diff --git a/calcium/dune b/calcium/dune
index cc84cbb..a2942e9 100644
--- a/calcium/dune
+++ b/calcium/dune
@@ -6,6 +6,9 @@
(foreign_stubs
(language c)
(names ocaml_calcium_utils)
+ (flags
+ (:include ../configure/c_flags.sexp)
+ :standard)
(include_dirs
lib
(lib flint)
@@ -25,7 +28,9 @@
"-Werror=implicit-function-declaration"
(:include ../configure/c_flags.sexp)
:standard)
- (c_library_flags "-lgmp -lmpfr")))
+ (c_library_flags
+ (:include ../configure/libs.sexp)
+ "-lgmp -lmpfr")))
(deps lib/ca.h)
(headers
(include "lib/ca.h" "string.h"))
diff --git a/configure/discover.ml b/configure/discover.ml
index ef7b777..4ca46c2 100644
--- a/configure/discover.ml
+++ b/configure/discover.ml
@@ -2,19 +2,21 @@ module C = Configurator.V1
let () =
C.main ~name:"discover" (fun c ->
- let conf =
+ let cflags, libs =
match C.Pkg_config.get c with
- | None -> []
+ | None -> [], []
| Some pc ->
- let cflags ~package =
+ let flags ~package =
match C.Pkg_config.query pc ~package with
- | None -> []
- | Some info -> info.cflags
+ | None -> [], []
+ | Some info -> info.cflags, info.libs
in
- let gmp = cflags ~package:"gmp" in
- let mpfr = cflags ~package:"mpfr" in
+ let gmp = flags ~package:"gmp" in
+ let mpfr = flags ~package:"mpfr" in
- gmp @ mpfr
+ (fst gmp) @ (fst mpfr),
+ (snd gmp) @ (snd mpfr)
in
- C.Flags.write_sexp "c_flags.sexp" conf)
+ C.Flags.write_sexp "c_flags.sexp" cflags;
+ C.Flags.write_sexp "libs.sexp" libs)
diff --git a/configure/dune b/configure/dune
index 617bc69..5bbdeb2 100644
--- a/configure/dune
+++ b/configure/dune
@@ -3,5 +3,5 @@
(libraries dune-configurator))
(rule
- (targets c_flags.sexp)
+ (targets c_flags.sexp libs.sexp)
(action (run ./discover.exe)))
diff --git a/flint/dune b/flint/dune
index 06a7e04..7f83395 100644
--- a/flint/dune
+++ b/flint/dune
@@ -6,6 +6,9 @@
(foreign_stubs
(language c)
(names ocaml_flint_utils)
+ (flags
+ (:include ../configure/c_flags.sexp)
+ :standard)
(include_dirs
flint
(lib zarith)))
@@ -21,7 +24,9 @@
"-Werror=implicit-function-declaration"
(:include ../configure/c_flags.sexp)
:standard)
- (c_library_flags "-lgmp -lmpfr")))
+ (c_library_flags
+ (:include ../configure/libs.sexp)
+ "-lgmp -lmpfr")))
(deps flint/flint.h flint/fmpz.h)
(headers
(include "flint/fmpz.h" "flint/fmpq.h" "string.h"))
Flint fails to compile for me with
This is because flint looks by default into
/usr/local
. On my system (macos M1 and x86_64 with macports) I need to call configure as./configure --with-gmp=/opt/local --with-mpfr=/opt/local --with-blas=/opt/local/include/lapack
to make flint configure.I still get some weird failures on ARM after that change:
Do you by chance know why these happen? If I enter the flint2 folder and configure and compile by hand it works fine.