Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HiGHS cmake instructions result in bad linking #1676

Open
silky opened this issue Mar 18, 2024 · 5 comments
Open

HiGHS cmake instructions result in bad linking #1676

silky opened this issue Mar 18, 2024 · 5 comments
Assignees

Comments

@silky
Copy link

silky commented Mar 18, 2024

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 :)

@Coloquinte
Copy link
Sponsor Contributor

Coloquinte commented Mar 18, 2024

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.

@metab0t
Copy link
Contributor

metab0t commented Apr 1, 2024

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.

@galabovaa
Copy link
Contributor

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

@silky
Copy link
Author

silky commented May 7, 2024

@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

@galabovaa
Copy link
Contributor

Thank you! I will edit cmake accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants