HiGHS cmake instructions result in bad linking
silky opened this issue · 6 comments
If you naively follow the README instructions for building HiGHS locally, you end up with a badly linked executable in /usr/local/bin
.
To reproduce:
> docker run -it ubuntu:latest
root@...:/# apt-get -y update && apt-get -y install build-essential git cmake protobuf-compiler
root@...:/# git clone https://github.com/ERGO-Code/HiGHS.git
root@...:/# cd HiGHS
root@...:/HiGHS# cmake -S . -B build
root@...:/HiGHS# cmake --build build
root@...:/HiGHS# cmake --install build
root@...:/HiGHS# highs
highs: error while loading shared libraries: libhighs.so.1: cannot open shared object file: No such file or directory
Note that the exe in ./build/bin/highs
works fine:
root@....:/HiGHS# ./build/bin/highs
Please specify filename in .mps|.lp|.ems format.
So I think it's just a problem with connecting up the LD_LIBRARY_PATH
or something; but probably a cmake expert will know the answer :)
Indeed it's a problem with seeing the new shared library. You need to run ldconfig
after installing, so the list of shared libraries is updated. Cmake doesn't do it for us
Alternatively you could just build with static linking: cmake -DBUILD_SHARED_LIBS=OFF
. Building the highs binary with static linking by default would avoid this kind of issues.
root@7faabfc1d615:/HiGHS# highs
highs: error while loading shared libraries: libhighs.so.1: cannot open shared object file: No such file or directory
root@7faabfc1d615:/HiGHS# ldconfig
root@7faabfc1d615:/HiGHS# highs
Please specify filename in .mps|.lp|.ems format.
You can also change the RPATH
for the highs executable like https://github.com/metab0t/highsbox/blob/edd84ac1767b9df82fba2cb635ea34ef87d95ab9/setup.py#L93
Ensure libhighs.so
is in the <your_highs_executable_path>/../lib
folder.
Run the following commands on Linux:
patchelf --set-rpath '$ORIGIN/../lib' <your_highs_executable_path>
On Mac, run:
install_name_tool -add_rpath '@loader_path/../lib' <your_highs_executable_path>
It is useful if you want to create a portable bundle of HiGHS without installing it in system directories.
I have made an attempt to address this issue in branch rpath-bin:
https://github.com/ERGO-Code/HiGHS/pull/1745/files
Would you please check whether this removes both
the need to modify paths on linux @silky
the need for your patch, @metab0t
@galabovaa naively following my initial instructions above, I now get
CMake Error at CMakeLists.txt:191 (cmake_policy):
Policy "CMP0138" is not known to this version of CMake.
on that branch :(
root@65347b9d05c1:/HiGHS# cmake --version
cmake version 3.22.1
Thank you! I will edit cmake accordingly