c-smile / sciter-sdk

Sciter is an embeddable HTML/CSS/scripting engine
http://sciter.com
Other
2.11k stars 224 forks source link

Consider use @rpath in install name of macOS's dylib #194

Open 7sDream opened 3 years ago

7sDream commented 3 years ago

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:

image

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.

image

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.

PS Same situation for `sciter-js-sdk`, but to avoid duplication, I only open issue in this repo.