Add RPATH for CUDA libraries in Linux builds

- Configure CMakeLists.txt to embed RPATH for CUDA library paths
- Includes $ORIGIN, CUDA 11.4 paths, and system library paths
- Eliminates need for LD_LIBRARY_PATH at runtime
- Binary can now find CUDA libraries automatically
This commit is contained in:
Shang Chieh Tseng
2025-10-30 12:51:59 +08:00
parent 46f1038724
commit bc8992d014

View File

@@ -36,6 +36,13 @@ if (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
set(CMAKE_INSTALL_RPATH "@loader_path")
endif()
# Set RPATH for Linux to find CUDA libraries at runtime
if (UNIX AND NOT APPLE)
set(CMAKE_BUILD_RPATH "$ORIGIN:/usr/local/cuda-11.4/lib64:/usr/local/cuda-11.4/targets/x86_64-linux/lib:/usr/lib64:/usr/local/lib64")
set(CMAKE_INSTALL_RPATH "$ORIGIN:/usr/local/cuda-11.4/lib64:/usr/local/cuda-11.4/targets/x86_64-linux/lib:/usr/lib64:/usr/local/lib64")
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
endif()
set(OLLAMA_BUILD_DIR ${CMAKE_BINARY_DIR}/lib/ollama)
set(OLLAMA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/ollama)