An error on "opam install lp-glpk"
I have installed glpk in the dictionary of "/opt/homebrew/Cellar/glpk/5.0", which means its version is 5.0
But when I try to install lp-glpk using opam install lp-glpk, there is an error:
[ERROR] The compilation of conf-glpk.1 failed at "cc -E test.c".
⬇ retrieved lp-glpk.0.4.0 (no changes)
#=== ERROR while compiling conf-glpk.1 ========================================#
# context 2.1.4 | macos/arm64 | ocaml.4.14.1 | https://opam.ocaml.org#8aa6c0b9
# path ~/.opam/default/.opam-switch/build/conf-glpk.1
# command ~/.opam/opam-init/hooks/sandbox.sh build cc -E test.c
# exit-code 1
# env-file ~/.opam/log/conf-glpk-15693-cbc34f.env
# output-file ~/.opam/log/conf-glpk-15693-cbc34f.out
### output ###
# [...]
# test.c:1:10: fatal error: 'glpk.h' file not found
# #include <glpk.h>
# ^~~~~~~~
# # 1 "test.c"
then I use export C_INCLUDE_PATH="/opt/homebrew/Cellar/glpk/5.0/include:$C_INCLUDE_PATH" to explicitly give the path to glpk.h.
but there is still an error here:
[ERROR] The compilation of lp-glpk.0.4.0 failed at "dune build -p lp-glpk -j 7".
#=== ERROR while compiling lp-glpk.0.4.0 ======================================#
# context 2.1.4 | macos/arm64 | ocaml.4.14.1 | pinned(git+https://github.com/ktahar/ocaml-lp.git#00d2df4e)
# path ~/.opam/default/.opam-switch/build/lp-glpk.0.4.0
# command ~/.opam/opam-init/hooks/sandbox.sh build dune build -p lp-glpk -j 7
# exit-code 1
# env-file ~/.opam/log/lp-glpk-16504-ebaaf8.env
# output-file ~/.opam/log/lp-glpk-16504-ebaaf8.out
### output ###
# [...]
# 4 warnings generated.
# File "src/lp-glpk/ffi/lib/dune", line 18, characters 0-389:
# 18 | (library
# 19 | (name lp_glpk_ffi)
# 20 | (public_name lp-glpk.ffi)
# ....
# 28 | (c_library_flags
# 29 | (:standard -lglpk))
# 30 | (libraries lp-glpk.bindings lp-glpk.types ctypes.stubs ctypes))
# (cd _build/default && /Users/wangkeyin/.opam/default/bin/ocamlmklib.opt -g -o src/lp-glpk/ffi/lib/lp_glpk_ffi_stubs src/lp-glpk/ffi/lib/lp_glpk_stubs.o -ldopt -lglpk)
# ld: library not found for -lglpk
# clang: error: linker command failed with exit code 1 (use -v to see invocation)
what's the problem here?
Looks like your linker cannot find the object file of glpk (something like libglpk.so).
I'm not pretty sure because I don't use MacOS. Maybe something like export LD_LIBRARY_PATH="/opt/homebrew/Cellar/glpk/5.0/lib:$LD_LIBRARY_PATH" helps.
(Please check if the object file exists there.)
But I think brew install glpk should configure your compiler and linker so that they can find the include / object files without setting C_INCLUDE_PATH / LD_LIBRARY_PATH manually :thinking:
Closing as this is not issue of the library.