admin管理员组文章数量:1399907
I am building a c++ project on Mac using cmake and cpack. The application will be distributed to other computer with different setups so I want to make it self-contained i.e all libraries should be loaded from $AppFolder/lib I tried setting:
install(FILES
"${HOMEBREW_PREFIX}/opt/openssl@3/lib/libssl.3.dylib"
"${HOMEBREW_PREFIX}/opt/openssl@3/lib/libcrypto.3.dylib"
"${HOMEBREW_PREFIX}/opt/libzip/lib/libzip.5.dylib"
DESTINATION lib)
# Ensure libraries are relocated properly and binaries can run standalone
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_MACOSX_RPATH True)
set(CMAKE_FIND_FRAMEWORK NEVER)
set(CMAKE_FIND_APPBUNDLE NEVER)
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
Still the binary is linked to the original paths. When I try to run the application on another computer that does not have brew installed it of corse fails.
otool -L MyAplication
/opt/brew/opt/openssl@3/lib/libssl.3.dylib (compatibility version 3.0.0, current version 3.0.0)
/opt/brew/opt/openssl@3/lib/libcrypto.3.dylib (compatibility version 3.0.0, current version 3.0.0)
/opt/brew/opt/libzip/lib/libzip.5.dylib (compatibility version 5.0.0, current version 5.5.0)
How do I make the application completely self contained without rebuilding it on every computer ?
I am building a c++ project on Mac using cmake and cpack. The application will be distributed to other computer with different setups so I want to make it self-contained i.e all libraries should be loaded from $AppFolder/lib I tried setting:
install(FILES
"${HOMEBREW_PREFIX}/opt/openssl@3/lib/libssl.3.dylib"
"${HOMEBREW_PREFIX}/opt/openssl@3/lib/libcrypto.3.dylib"
"${HOMEBREW_PREFIX}/opt/libzip/lib/libzip.5.dylib"
DESTINATION lib)
# Ensure libraries are relocated properly and binaries can run standalone
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_MACOSX_RPATH True)
set(CMAKE_FIND_FRAMEWORK NEVER)
set(CMAKE_FIND_APPBUNDLE NEVER)
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
Still the binary is linked to the original paths. When I try to run the application on another computer that does not have brew installed it of corse fails.
otool -L MyAplication
/opt/brew/opt/openssl@3/lib/libssl.3.dylib (compatibility version 3.0.0, current version 3.0.0)
/opt/brew/opt/openssl@3/lib/libcrypto.3.dylib (compatibility version 3.0.0, current version 3.0.0)
/opt/brew/opt/libzip/lib/libzip.5.dylib (compatibility version 5.0.0, current version 5.5.0)
How do I make the application completely self contained without rebuilding it on every computer ?
Share Improve this question asked Mar 25 at 20:31 user2555515user2555515 1,07111 silver badges21 bronze badges1 Answer
Reset to default 0This appeared to do the trick:
install(CODE "
execute_process(COMMAND install_name_tool -change ${HOMEBREW_PREFIX}/opt/openssl@3/lib/libssl.3.dylib @rpath/libssl.3.dylib \${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME})
execute_process(COMMAND install_name_tool -change ${HOMEBREW_PREFIX}/opt/openssl@3/lib/libcrypto.3.dylib @rpath/libcrypto.3.dylib \${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME})
execute_process(COMMAND install_name_tool -change ${HOMEBREW_PREFIX}/opt/libzip/lib/libzip.5.dylib @rpath/libzip.5.dylib \${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME})
")
本文标签: macosHow to set RPATH in cmake for MacStack Overflow
版权声明:本文标题:macos - How to set RPATH in cmake for Mac? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744170045a2593737.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论