Loading a x86 shared library on a macBook M2

Hi!

I’m moving a Julia project from an old MacBook Pro (2017) with an Intel Core i7 chip to a brand new one (2023) with the M2 Max.

My project requires a C shared library which is not yet available on this new platform, so I copied the x86 version to the standard location on the M2 computer.

When I call a function that uses that library, I get the following error message complaining about “incompatible architecture”:

julia> include(JMtk15_test * "src/jMtkVersion_tst.jl")
jMtkVersion_tst

julia> version = jMtkVersion_tst();
ERROR: could not load library "/Applications/Mtk-1.5.0/lib/libMisrToolkit.so.1.5.0"
dlopen(/Applications/Mtk-1.5.0/lib/libMisrToolkit.so.1.5.0, 0x0001): tried: '/Applications/Mtk-1.5.0/lib/libMisrToolkit.so.1.5.0' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Mtk-1.5.0/lib/libMisrToolkit.so.1.5.0' (no such file), '/Applications/Mtk-1.5.0/lib/libMisrToolkit.so.1.5.0' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
Stacktrace:
 [1] jMtkVersion
   @ ~/Projects/MISR/MISR_Toolkit/JMtk15/src/jMtkVersion.jl:26 [inlined]
 [2] jMtkVersion_tst()
   @ Main ~/Projects/MISR/MISR_Toolkit/JMtk15/test/src/jMtkVersion_tst.jl:39
 [3] top-level scope
   @ REPL[6]:1

Since Rosetta has been previously installed, I was expecting this to work. This library is correctly found, but cannot be loaded. What do I need to do to enable Julia on the M2 chip to recognize and use that shared library compiled for the x86 chip? Thanks for your help.

Not sure but I think that you need to use x86 version of Julia via Rosetta.

1 Like

Yes, you can’t mix libraries for different architectures within the same process. Rosetta works on the entire process, so you need an x86_64 Julia run under Rosetta to load an x86_64 library.

4 Likes

Thanks to both of you for addressing this issue. Here are follow-up questions, then:

  • How is this implemented? Do I need to install a new, separate ‘x86_64’ version of Julia?

  • If so, how can I prevent the ‘x86_64’ version from replacing the working ‘arm64’ version, as I would like to use the native ‘arm64’ version whenever possible?

  • How do I manage multiple instances of Julia on the same platform? In particular, how do I call either version specifically, depending on the use case?

Thanks for clarifying those points.

1 Like

Great! Thanks a lot @giordano.