MacOS Dynamic library issues using a Makefile written for Linux platforms

144 Views Asked by At

I have to build a Geant4 code which was made on Linux and I have to make it work on MacOS. The problem is that the code requires a custom library (libTvectors), which I do have and I am compiling. However, it seems to create the library with the extension .so but the Geant4 program requests .dylib.

I have this warning when I build the program with a makefile:

ld: warning: dylib (../Tvectors/libTvectors.so) was built for newer macOS version (13.5) than being linked (13.0)

When I launch the executable I have this error:

Library not loaded: /Users/cristinaclisu/Work/nucsim_short/Tvectors/ Referenced from: <90602448-3E34-3328-9F82-F64FA34D4933> /Users/cristinaclisu/Work/nucsim_short/build/nucsim Reason: tried: '/usr/local/Cellar/root/6.28.04_1/lib/root/' (not a file), '/Users/cristinaclisu/Work/nucsim_short/Tvectors/' (not a file), '/System/Volumes/Preboot/Cryptexes/OS/Users/cristinaclisu/Work/nucsim_short/Tvectors/' (no such file), '/Users/cristinaclisu/Work/nucsim_short/Tvectors/' (not a file), '/usr/local/lib/' (not a file), '/usr/lib/' (not a file, not in dyld cache) Abort trap: 6

Could anyone help me figure out what I should do to fix it? Is there a way to make libTvectors be created as a dylib? Is there any way to tell my Geant4 program to look for the .so? Or is this another issue I am missing?

Installed Root (required by libTvectors) successfully. Tested and works. Installed Geant4 (required by the app) successfully. Tested and works. Compiled the libTvectors library. No errors after make. Compiled the Geant4 app, no errors except a warning.

On trying to execute the program, got the above error.

1

There are 1 best solutions below

0
Siguza On

The short story is that dylibs embed the path at which they expect to be installed, and that path is copied into binaries linking against them at link-time. This path is broken for your libTvectors.so.

A quick fix should be to run these two commands:

install_name_tool -id /Users/cristinaclisu/Work/nucsim_short/Tvectors/libTvectors.so /Users/cristinaclisu/Work/nucsim_short/Tvectors/libTvectors.so
codesign -f -s - /Users/cristinaclisu/Work/nucsim_short/Tvectors/libTvectors.so

And then rebuild anything that links against libTvectors.so.

Note that your setup will break if you ever decide to move your project folder to a different path. For a more comprehensive look at install names and how to handle them, see this other answer of mine.