This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Add $ORIGIN/../../../../lib to rpath if BUILD_SHARED_LIBS or LLVM_LINK_LLVM_DYLIB on *nix
ClosedPublic

Authored by MaskRay on Dec 21 2019, 3:21 PM.

Details

Summary

lib/python2.7/dist-packages/lldb/_lldb.so is a symlink to lib/liblldb.so,
which depends on lib/libLLVM*.so (-DBUILD_SHARED_LIBS=ON) or lib/libLLVM-10git.so
(-DLLVM_LINK_LLVM_DYLIB=ON). Add an additional rpath $ORIGIN/../../../../lib so
that _lldb.so can be loaded from Python.

This fixes an import error from lib/python2.7/dist-packages/lldb/__init__.py

from . import _lldb
ImportError: libLLVMAArch64CodeGen.so.10git: cannot open shared object file: No such file or directory

The following configurations will work:

  • -DBUILD_SHARED_LIBS=ON
  • -DBUILD_SHARED_LIBS=OFF -DLLVM_LINK_LLVM_DYLIB=ON
  • -DBUILD_SHARED_LIBS=OFF -DLLVM_LINK_LLVM_DYLIB=ON -DCLANG_LINK_CLANG_DYLIB=ON (-DCLANG_LINK_CLANG_DYLIB=ON depends on -DLLVM_LINK_LLVM_DYLIB=ON)

Diff Detail

Event Timeline

MaskRay created this revision.Dec 21 2019, 3:21 PM
MaskRay marked an inline comment as done.Dec 21 2019, 3:24 PM
MaskRay added inline comments.
lldb/source/API/CMakeLists.txt
124

The extra_libdir logic is copied from llvm/cmake/modules/AddLLVM.cmake llvm_setup_rpath.

Yeah, not requiring LD_LIBRARY_PATH in the BUILD_SHARED_LIBS build would be nice. The fix isn't particularly pretty, but I don't know if there is a better way to do that (besides the improvements in inline comments).

lldb/source/API/CMakeLists.txt
117

I think this would work on APPLE (which is subsumed by UNIX). Though I don't know if anyone there actually uses BUILD_SHARED_LIBS...

124

Instead of copying that you should do something like set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "whatever") to just add the new entry.

BTW, isn't a LLVM_LINK_LLVM_DYLIB build suffering from the same problem? Should that be included here too?

MaskRay updated this revision to Diff 235170.Dec 23 2019, 11:41 AM
MaskRay marked 3 inline comments as done.
MaskRay retitled this revision from [CMake] Add $ORIGIN/../../../../lib to rpath if BUILD_SHARED_LIBS AND UNIX to [CMake] Add $ORIGIN/../../../../lib to rpath if BUILD_SHARED_LIBS or LLVM_LINK_LLVM_DYLIB on *nix.
MaskRay edited the summary of this revision. (Show Details)

Make -DLLVM_LINK_LLVM_DYLIB=ON work

lldb/source/API/CMakeLists.txt
117

I assume APPLE -DBUILD_SHARED_LIBS=On works as-is. I will add AND NOT APPLE.

124

Thanks for the suggestion! Will apply.

labath accepted this revision.Jan 6 2020, 6:57 AM

Thanks. I think this is fine now.

This revision is now accepted and ready to land.Jan 6 2020, 6:57 AM
This revision was automatically updated to reflect the committed changes.