Skip to content

create_library link error in MacOS #1107

@mojaie

Description

@mojaie

Environments:

  • Apple M3
  • MacOS 26.3.1
  • Julia 1.12.6
  • PackageCompiler v2.3.0

Now create_library seems to set @executable_path for MacOS, but the libraries are not always in the executable path in many use cases.

% otool -l /***/julia/libmolgraphjl/lib/libmolgraphjl.dylib | grep LC_RPATH -A2
          cmd LC_RPATH
      cmdsize 32
         path @executable_path (offset 12)
--
          cmd LC_RPATH
      cmdsize 40
         path @executable_path/julia (offset 12)

I'm working on Python projects that internally uses Julia packages as a library, and encounters some linking problems. Possible workarounds are

  1. Relinking
% install_name_tool -add_rpath /***/julia/libmolgraphjl/lib/julia /***/julia/libmolgraphjl/lib/libmolgraphjl.dylib

but now this can produce an error shown as below.

error: /***/install_name_tool: changing install names or rpaths can't be redone for: /***/julia/libmolgraphjl/lib/libmolgraphjl.dylib (for architecture arm64) because larger updated load commands do not fit (the program must be relinked, and you may need to use -headerpad or -headerpad_max_install_names)
  1. Environment variables
# in .zprofile
export DYLD_FALLBACK_LIBRARY_PATH=/***/julia/libmolgraphjl/lib:/***/julia/libmolgraphjl/lib/julia

This works well in the default terminal, but DYLD_*** env vars will be ignored in some shell environment (e. g. Jupyter in VSCode)

  1. Build with @loader_path

This seems to be the most straightforward solution.

function rpath_sysimage()
Sys.iswindows() ? `` :
Sys.isapple() ? `-Wl,-rpath,'@executable_path' -Wl,-rpath,'@executable_path/julia'` :
`-Wl,-rpath,\$ORIGIN:\$ORIGIN/julia`
end

Temporarily overwriting this function as like below seems to work at least in my environment.

import PackageCompiler

function PackageCompiler.rpath_sysimage()
    Sys.iswindows() ? `` :
    Sys.isapple()   ? `-Wl,-rpath,'@loader_path' -Wl,-rpath,'@loader_path/julia'` :
                      `-Wl,-rpath,\$ORIGIN:\$ORIGIN/julia`
end

Of course this may affect other sysimage functions, so there should be a specific rpath function for create_library

function rpath_sysimage_library()
    Sys.iswindows() ? `` :
    Sys.isapple()   ? `-Wl,-rpath,'@loader_path' -Wl,-rpath,'@loader_path/julia'` :
                      `-Wl,-rpath,\$ORIGIN:\$ORIGIN/julia`
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions