dylib set by rpath is not loaded in OS X - macos

I am making a package manager, and would like to ensure the packages use the correct dependent library by setting rpath option at compile time. But it surprised me in OS X (10.11), here is the problem:
$ otool -L /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
/opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib (compatibility version 18.0.0, current version 18.1.0)
/opt/starman/software/mpc/1.0.3/6058925218009b8ab17e07333dc54de334134f6e/lib/libmpc.3.dylib (compatibility version 4.0.0, current version 4.0.0)
/opt/starman/software/mpfr/3.1.4/f142dfcda3b56650a8c9cfe2fdd09ffdf7283a00/lib/libmpfr.4.dylib (compatibility version 6.0.0, current version 6.4.0)
/opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib (compatibility version 14.0.0, current version 14.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
see gmp version is 14.0.0.
$ /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: Library not loaded: /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
Referenced from: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
Reason: Incompatible library version: f951 requires version 14.0.0 or later, but libgmp.10.dylib provides version 13.0.0
Trace/BPT trap: 5
It says gmp in the correct path is not loaded since its version is 13.0.0, but it is 14.0.0! I know I have an older version gmp installed in another path, so after I remove its lib path from DYLD_LIBRARY_PATH, the problem is gone, but shouldn't rpath solve this problem?
Why dyld prints the correct path of gmp, but actually uses the wrong old? Is there any tricks in OS X? Thanks for help!
EDIT 1:
The version of /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib is checked as
$ otool -l /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
...
cmdsize 120
name /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib (offset 24)
time stamp 1 Thu Jan 1 08:00:01 1970
current version 14.0.0
compatibility version 14.0.0
...
And the older gmp is
$ otool -l /opt/software/gmp/6.0.0a/0/lib/libgmp.10.dylib
...
name #rpath/lib/libgmp.dylib (offset 24)
time stamp 1 Thu Jan 1 08:00:01 1970
current version 13.0.0
compatibility version 13.0.0
...
EIDT 2
According to 0xced, I run debug the loading process as (The full output is here):
$ export DYLD_PRINT_LIBRARIES="1"
$ /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: loaded: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: loaded: /usr/lib/libiconv.2.dylib
dyld: loaded: /opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib
dyld: loaded: /opt/software/packman.active/lib/libmpc.3.dylib
dyld: loaded: /opt/software/packman.active/lib/libmpfr.4.dylib
dyld: loaded: /opt/software/packman.active/lib/libgmp.10.dylib
dyld: unloaded: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: unloaded: /opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib
dyld: unloaded: /opt/software/packman.active/lib/libmpc.3.dylib
dyld: unloaded: /opt/software/packman.active/lib/libmpfr.4.dylib
dyld: unloaded: /opt/software/packman.active/lib/libgmp.10.dylib
dyld: Library not loaded: /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
Referenced from: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
Reason: Incompatible library version: f951 requires version 14.0.0 or later, but libgmp.10.dylib provides version 13.0.0
Trace/BPT trap: 5

I don't understand why the f951 binary would load /opt/software/gmp/6.0.0a/0/lib/libgmp.10.dylib (version 13) rather than /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib (version 14) which is specified with an absolute path and not a relative #rpath.
Maybe it’s loaded indirectly via another library, e.g. libisl.15.dylib, libmpc.3.dylib or libmpfr.4.dylib which could have an #rpath reference to libgmp.10.dylib?
To diagnose this issue, I suggest you to run the main executable like this:
$ DYLD_PRINT_RPATHS=YES /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
This will print all rpath expansions (both failure and success) and will probably give you the answer to your question.

Related

Omnet++ : Could not determine GDB version using command: lldbmi2 --version dyld: Library not loaded: #rpath/LLDB.framework/LLDB

I tried to debug a script on omnet++ getting the following message:
Could not determine GDB version using command: lldbmi2 --version dyld: Library not loaded: #rpath/LLDB.framework/LLDB Reason: image not found
Can you help me?
PS: i am using MacBook Air with Catalina version 10.15.7 . I don't have Xcode installed

AdaCore gnatstudio builds but won't run

Mac mini (2018)
OSX 10.15.5
XCode 11.5
GNAT 2020
Miniconda environment python 3.7.7
I have built gnatstudio from https://github.com/AdaCore/gps-master.
However, the command gnatstudio/obj/gnatstudio fails with:
dyld: Library not loaded: /gnatmail/sandbox/a2c2/x86_64-darwin/gcc-c/pkg/lib/libstdc++.6.dylib
Referenced from: /System/Volumes/Data/Applications_Packages/gps-master/gnatstudio/obj/gnatstudio
Reason: image not found
zsh: abort gnatstudio/obj/gnatstudio
I can find no reference to /gnatmail/sandbox/a2c2/x86_64-darwin/gcc-c/pkg/lib/libstdc++.6.dylib in my gps build instructions; not in any Makefile or gpr.
I have found libstdc++.6.dylib in /opt/GNAT/2020/lib, /opt/GNAT/2019/lib/gps and a few other less relevant locations.

Incompatible library version running EiffelStudio

I installed EiffelStudio like this:
1) Downloaded Eiffel_15.12_gpl_98497-macosx-x86-64.tar.bz2 from official page.
2)
cd /usr/local
tar xvfj /path/Eiffel_15.12.tar.bz2
3)
export ISE_EIFFEL=/usr/local/Eiffel_15.12
export ISE_PLATFORM=macosx-x86-64
export PATH=$PATH:$ISE_EIFFEL/studio/spec/$ISE_PLATFORM/bin
Then I type "ec" to run the command-line compiler and this is the output:
dyld: Library not loaded: /opt/local/lib/libiconv.2.dylib
Referenced from: /usr/local/Eiffel_15.12/studio/spec/macosx-x86-64/bin/ec
Reason: Incompatible library version: ec requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0
Trace/BPT trap: 5
Any solution?
PS: Im using OSX 10.11.4
PPS: When i run
otool -L $(which ec)
I get
/usr/local/Eiffel_15.12/studio/spec/macosx-x86-64/bin/ec:
/opt/local/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
...
EDIT: I found this link that helps me
https://stackoverflow.com/a/19016967/6273708
But know the error message is
dyld: Library not loaded: /opt/local/lib/libgtk-x11-2.0.0.dylib
Referenced from: /usr/local/Eiffel_15.12/studio/spec/macosx-x86-64/bin/ec
Reason: image not found
Trace/BPT trap: 5

Undefined symbols for architecture while using dylib C++

This is the procedure I am following to create dylib and using it ,please help me I am new to dylib .
I am creating dylib for c++ in xcode I have given Installation Directory #rpath this is my C++ code
Add.hpp:
#define EXPORT __attribute__((visibility("default")))
class Add
{
public:
EXPORT void HelloWorld(const char *);
EXPORT int AddTwo(int a,int b);
};
Add.cpp:
void Add::HelloWorld(const char * s)
{
AddPriv *theObj = new AddPriv;
theObj->HelloWorldPriv(s);
delete theObj;
};
int Add::AddTwo(int a, int b)
{
return a+b;
}
After creating dylib in other project using Copy files in build phases, copying it to Frameworks, I am able to see it in Sample.App/Contents/Frameworks/Mylib.dylib. In Build Settings, Runpath Search Paths is set to #executable_path/../Frameworks. I added header in root folder given Header Search Paths $(SRCROOT).
The error I get is:
Undefined symbols for architecture x86_64:
"Add::AddTwo(int, int)", referenced from:
-[ViewController viewDidLoad] in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Edit:
$ nm -gU ****/AddTest.app/Contents/Frameworks/libAdd.dylib
0000000000001170 T __ZN3Add10HelloWorldEPKc
0000000000001220 T __ZN3Add6AddTwoEii
able to see symboles in lib and otool output is:
$ otool -L libAdd.dylib
#rpath/libAdd.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
resolved by adding library to Link Binary with Libraries in build phases

DYLD: Incompatible library version for cmake

OS: Mac 10.11.1
When I tried to "cmake", I got the following error message
dyld: Library not loaded: /opt/local/lib/libexpat.1.dylib
Referenced from: /opt/local/bin/cmake
Reason: Incompatible library version: cmake requires version 8.0.0 or later, but libexpat.1.dylib provides version 7.0.0
Trace/BPT trap: 5
I also installed a fresh copy of CMake application, by running "/Applications/CMake.app/Contents/bin/ccmake", I got the following error message
dyld: Library not loaded: /opt/local/lib/liblzma.5.dylib
Referenced from: /opt/local/lib/libTIFF.dylib
Reason: Incompatible library version: libTIFF.dylib requires version 8.0.0 or later, but liblzma.5.dylib provides version 6.0.0
Trace/BPT trap: 5
Any help would be highly appreciated! Thanks!
It now works after I commented out the dyld line in bash_profile...

Resources