HiGHS icon indicating copy to clipboard operation
HiGHS copied to clipboard

macos: Wrong usage of MACOSX_RPATH (when using -DFAST_BUILD=OFF)

Open Mizux opened this issue 6 months ago • 2 comments

In your CMake based build, MACOSX_RPATH is wrongly used here: https://github.com/ERGO-Code/HiGHS/blob/364c83a51e44ba6c27def9c8fc1a49b1daf5ad5c/highs/CMakeLists.txt#L46 so dylib is build with absolute path and don't use @rpath...

note: Spotted in https://github.com/google/or-tools/issues/4674#issuecomment-2963390936 note2: same issue here: https://github.com/scipopt/soplex/issues/49 and https://github.com/scipopt/scip/issues/154

Protocol

cmake -S. -Bbuild -DFAST_BUILD=OFF
cmake --build build --config Release -j8
# Check path inside the shared library
otool -L build/lib/libhighs.dylib  

Observed

build/lib/libhighs.dylib:
    **/Users/corentinl/work/HiGHS/build/lib/libhighs.1.11.dylib (compatibility version 1.11.0, current version 1.11.0)**
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.12)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1900.180.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)

Expected

**@rpath/libhighs.1.11.dylib (compatibility version 1.11.0, current version 1.11.0)**

Explanation

  1. MACOS_RPATH is a boolean property which must be set to TRUE or FALSE If TRUE, the default, cmake will use @rpath as directory portion (aka prefix) of the install_name (otool LC_ID_DYLIB) note: CMP0042 set it to TRUE by default
  2. Here, you are storing a "path" (i.e. the string ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) into a variable which should be use to store TRUE or FALSE and CMake if(string) is always evaluated to FALSE (unless store a "TRUE" constant which is not the case here) leading to NOT using @rpath directory prefix...
  3. Your projects already use set(CMAKE_MACOSX_RPATH TRUE) in root CMakeLists.txt, which already default set MACOS_RPATH to TRUE, so you should just stop playing with MACOSX_RPATH Target property IMHO...
  4. side note: To change the runpath (otool LC_RPATH) (e.g. to set it to @loader_path) you may use the INSTALL_RPATH target property...

ref: https://cmake.org/cmake/help/latest/command/if.html#string https://cmake.org/cmake/help/latest/variable/CMAKE_MACOSX_RPATH.html https://cmake.org/cmake/help/latest/prop_tgt/MACOSX_RPATH.html https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html

Mizux avatar Jun 12 '25 15:06 Mizux

With the fix:

diff --git a/highs/CMakeLists.txt b/highs/CMakeLists.txt
index 50301433d..a8b509d5f 100644
--- a/highs/CMakeLists.txt
+++ b/highs/CMakeLists.txt
@@ -43,7 +43,8 @@ if(NOT FAST_BUILD)
   set_target_properties(libhighs PROPERTIES
     OUTPUT_NAME "highs"
     PDB_NAME "libhighs"
-    MACOSX_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+    #MACOSX_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
+  )
 
   if(ZLIB AND ZLIB_FOUND)
     target_link_libraries(libhighs ZLIB::ZLIB)

Protocol

cmake --build build --config Release -j8
otool -L build/lib/libhighs.dylib

Observed

build/lib/libhighs.dylib:
	@rpath/libhighs.1.11.dylib (compatibility version 1.11.0, current version 1.11.0)
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.12)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1900.180.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)

Mizux avatar Jun 12 '25 15:06 Mizux

Thanks

jajhall avatar Jun 13 '25 08:06 jajhall

Closed by https://github.com/ERGO-Code/HiGHS/pull/2412

galabovaa avatar Jun 23 '25 20:06 galabovaa