Consider use @rpath in install name of macOS's dylib
7sDream opened this issue · comments
Current install name is /usr/local/lib/sciter-osx-64.dylib
:
foo@bar:~/Cloud/SDK/sciter-sdk/bin.osx$ otool -D sciter-osx-64.dylib
sciter-osx-64.dylib:
/usr/local/lib/sciter-osx-64.dylib
When link with it, at runtime, executable file will try to open /usr/local/lib/sciter-osx-64.dylib
only , and fails:
For now, my workaround is using install_name_tool
after build to change this path in executable file to use @rpath
:
# Change RPATH
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change /usr/local/lib/sciter-osx-64.dylib @rpath/sciter-osx-64.dylib $<TARGET_FILE:${PROJECT_NAME}>
COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path" $<TARGET_FILE:${PROJECT_NAME}>
)
The second command, add @executable_path
to rpath, is a common step, and is irrelevant to this issue
This works for me, but after a long digging.
So how about we change the default install name to use @rpath
? IIRC, it is officially recommended.
There are also many similar issue/pr in other projects, like:
etc, can be used as a reference.