rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.72k stars 12.64k forks source link

building dynamic libraries on mac sets id/name for linker to something questionable #121674

Open vmchale opened 7 months ago

vmchale commented 7 months ago

If I build a "cdylib", it tells the linker that the library is located in the target/release directory.

Here is the output for otool -l:

Load command 4
          cmd LC_ID_DYLIB
      cmdsize 96
         name /Users/vanessa/dev/rust/forks/regex/target/release/deps/librure.dylib (offset 24)
   time stamp 1 Wed Dec 31 19:00:01 1969
      current version 0.0.0
compatibility version 0.0.0

This means I can't install the shared library by copying the .dylib to /usr/local/lib; I have to run install_name_tool on the build result before distributing.

I think building a library should set the name to something like @rpath/librure.dylib

bjorn3 commented 7 months ago

Duplicate of https://github.com/rust-lang/rust/issues/28640? https://github.com/rust-lang/rust/issues/114445 seems related too.

vmchale commented 7 months ago

Duplicate of #28640? #114445 seems related too.

I think it's related to #28640 but not a duplicate. The linker command in this case is LC_ID_DYLIB rather than LC_LOAD_DYLIB.

I think it's different from #114445 since this is about rustc's output rather than rustc itself, though the problem with rustcs output is mentioned in one of the comments.

bjorn3 commented 7 months ago

I don't think rustc tells the linker to set the install name to any value.

I think building a library should set the name to something like @rpath/librure.dylib

I just found that there is already an unstable option for this: -Zosx-rpath-install-name Rustc itself is built with this option enabled.