macos - How to set RPATH in cmake for Mac? - Stack Overflow

I am building a c++ project on Mac using cmake and cpack. The application will be distributed to other

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

This 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

相关推荐

  • macos - How to set RPATH in cmake for Mac? - Stack Overflow

    I am building a c++ project on Mac using cmake and cpack. The application will be distributed to other

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信