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})
")
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744170047a4561491.html
评论列表(0条)