@@ -801,6 +801,9 @@ if(EXECUTORCH_BUILD_PYBIND)
801801 torch
802802 )
803803
804+ # RPATH for _portable_lib.so
805+ set (_portable_lib_rpath "$ORIGIN/../../../torch/lib" )
806+
804807 if (EXECUTORCH_BUILD_EXTENSION_MODULE)
805808 # Always use static linking for pybindings to avoid runtime symbol
806809 # resolution issues
@@ -835,6 +838,7 @@ if(EXECUTORCH_BUILD_PYBIND)
835838
836839 if (EXECUTORCH_BUILD_QNN)
837840 list (APPEND _dep_libs qnn_executorch_backend)
841+ string (APPEND _portable_lib_rpath ":$ORIGIN/../../backends/qualcomm" )
838842 endif ()
839843
840844 if (EXECUTORCH_BUILD_ENN)
@@ -886,19 +890,20 @@ if(EXECUTORCH_BUILD_PYBIND)
886890 target_compile_options (portable_lib PUBLIC ${_pybind_compile_options} )
887891 target_link_libraries (portable_lib PRIVATE ${_dep_libs} )
888892
889- # Set RPATH to find PyTorch libraries relative to the installation location
890- # This goes from executorch/extension/pybindings up to site-packages, then to
891- # torch/lib. Don't do this to APPLE, as it will error out on the following
892- # error:
893+ # Set RPATH to find PyTorch and backend libraries relative to the installation
894+ # location. This goes from executorch/extension/pybindings up to
895+ # site-packages, then to torch/lib. If QNN is enabled, also add
896+ # backends/qualcomm/. Don't do this to APPLE, as it will error out on the
897+ # following error:
893898 #
894899 if (APPLE )
895900 # Skip setting @loader_path for APPLE, since it causes error like ld:
896901 # duplicate LC_RPATH '@loader_path' in '<site-packages>/torch/lib/
897902 # libtorch_cpu.dylib'
898903 else ()
899904 set_target_properties (
900- portable_lib PROPERTIES BUILD_RPATH "$ORIGIN/../../../torch/lib "
901- INSTALL_RPATH "$ORIGIN/../../../torch/lib "
905+ portable_lib PROPERTIES BUILD_RPATH "${_portable_lib_rpath} "
906+ INSTALL_RPATH "${_portable_lib_rpath} "
902907 )
903908 endif ()
904909
0 commit comments