From: Georgios Petasis on
Hi all,

I am facing a problem with two dynamic libraries that implement some
commands in C.

I have library A, which depends only on system libraries (libstdc++ &
libSystem.B), which gets loaded ok in Tcl:

otool -L CDM/Darwin/x86_64/libCDM.dylib CDM/Darwin/x86_64/libCDM.dylib:
libCDM.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version
7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
123.0.0)

I have then library B, which depends on A:

otool -L share/modules/HBrill/Darwin/x86_64/libHBrill.dylib
share/modules/HBrill/Darwin/x86_64/libHBrill.dylib:
libHBrill.dylib (compatibility version 0.0.0, current version 0.0.0)
libCDM.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version
7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
123.0.0)

So, I have loaded A through "load", but when I try to load B, I get an
error:

(Loading Library:
/Users/petasis/Ellogon/share/modules/HBrill/Darwin/x86_64/libHBrill.dylib
Error:
dlopen(/Users/petasis/Ellogon/share/modules/HBrill/Darwin/x86_64/libHBrill.dylib,
10): Library not loaded: libCDM.dylib
Referenced from:
/Users/petasis/Ellogon/share/modules/HBrill/Darwin/x86_64/libHBrill.dylib
Reason: image not found

But libCDM.dylib has been loaded by the process, and its commands are
available.

Any idea on what may be wrong?

George
From: Georgios Petasis on
Στις 17/7/2010 13:40, ο/η Georgios Petasis έγραψε:
> Hi all,
>
> I am facing a problem with two dynamic libraries that implement some
> commands in C.
>
> I have library A, which depends only on system libraries (libstdc++ &
> libSystem.B), which gets loaded ok in Tcl:
>
> otool -L CDM/Darwin/x86_64/libCDM.dylib CDM/Darwin/x86_64/libCDM.dylib:
> libCDM.dylib (compatibility version 0.0.0, current version 0.0.0)
> /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version
> 7.9.0)
> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
> 123.0.0)
>
> I have then library B, which depends on A:
>
> otool -L share/modules/HBrill/Darwin/x86_64/libHBrill.dylib
> share/modules/HBrill/Darwin/x86_64/libHBrill.dylib:
> libHBrill.dylib (compatibility version 0.0.0, current version 0.0.0)
> libCDM.dylib (compatibility version 0.0.0, current version 0.0.0)
> /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version
> 7.9.0)
> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
> 123.0.0)
>
> So, I have loaded A through "load", but when I try to load B, I get an
> error:
>
> (Loading Library:
> /Users/petasis/Ellogon/share/modules/HBrill/Darwin/x86_64/libHBrill.dylib
> Error:
> dlopen(/Users/petasis/Ellogon/share/modules/HBrill/Darwin/x86_64/libHBrill.dylib,
> 10): Library not loaded: libCDM.dylib
> Referenced from:
> /Users/petasis/Ellogon/share/modules/HBrill/Darwin/x86_64/libHBrill.dylib
> Reason: image not found
>
> But libCDM.dylib has been loaded by the process, and its commands are
> available.
>
> Any idea on what may be wrong?
>
> George

Anyone?
From: Donal K. Fellows on
On Jul 17, 11:40 am, Georgios Petasis <peta...(a)iit.demokritos.gr>
wrote:
> I am facing a problem with two dynamic libraries that implement some
> commands in C.
>
> I have library A, which depends only on system libraries (libstdc++ &
> libSystem.B), which gets loaded ok in Tcl:
[...]
> I have then library B, which depends on A:
[...]
> So, I have loaded A through "load", but when I try to load B, I get an
> error:
[...]
> But libCDM.dylib has been loaded by the process, and its commands are
> available.
>
> Any idea on what may be wrong?

Curious. Looks like it is not registering the fact that the library is
present. (This might be a deliberate move on Apple's part to stop code
from getting at APIs that it shouldn't have anything to do with.)

Since both libraries are Tcl-aware, maybe you could try having one
export a stubbed ABI that the other uses, with the other using the
first through that. (The two are stitched together with a wrapper
round [package require].) For an example of how to build the library
so as to do that, see the TclOO-as-extension-package code. (Adapting
the consumer side should be easy enough.)

Donal.
From: Georgios Petasis on
Στις 20/7/2010 08:49, ο/η Donal K. Fellows έγραψε:
> On Jul 17, 11:40 am, Georgios Petasis<peta...(a)iit.demokritos.gr>
> wrote:
>> I am facing a problem with two dynamic libraries that implement some
>> commands in C.
>>
>> I have library A, which depends only on system libraries (libstdc++&
>> libSystem.B), which gets loaded ok in Tcl:
> [...]
>> I have then library B, which depends on A:
> [...]
>> So, I have loaded A through "load", but when I try to load B, I get an
>> error:
> [...]
>> But libCDM.dylib has been loaded by the process, and its commands are
>> available.
>>
>> Any idea on what may be wrong?
>
> Curious. Looks like it is not registering the fact that the library is
> present. (This might be a deliberate move on Apple's part to stop code
> from getting at APIs that it shouldn't have anything to do with.)
>
> Since both libraries are Tcl-aware, maybe you could try having one
> export a stubbed ABI that the other uses, with the other using the
> first through that. (The two are stitched together with a wrapper
> round [package require].) For an example of how to build the library
> so as to do that, see the TclOO-as-extension-package code. (Adapting
> the consumer side should be easy enough.)
>
> Donal.

Yes, it is really strange. I am not sure that I understood the stubbed
ABI solution you propose (the library is linked by many dlls actually,
not all tcl-related) :-)

However, looking (for many hours) on the net, led me to a deprecated
function(!):
https://developer.mozilla.org/en/Using_Dependent_Libraries_In_Extension_Components

There is a function named NSAddImage:
http://developer.apple.com/mac/library/documentation/DeveloperTools/Reference/MachOReference/Reference/reference.html#//apple_ref/c/func/NSAddImage

If I call this function with the shared library that the whole
application must see, with the parameters
NSADDIMAGE_OPTION_RETURN_ON_ERROR |
NSADDIMAGE_OPTION_WITH_SEARCHING |
NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME

it does the obvious: the loaded shared library is visible to other
shared libraries, as it should.

Of course, the problem is that the function is already deprecated.
So, I have to find an alternative to this :-(

Regards,

George
From: Alexandre Ferrieux on
On Jul 20, 11:46 am, Georgios Petasis <peta...(a)iit.demokritos.gr>
wrote:
> Στις 20/7/2010 08:49, ο/η Donal K. Fellows έγραψε:
>
>
>
>
>
> > On Jul 17, 11:40 am, Georgios Petasis<peta...(a)iit.demokritos.gr>
> > wrote:
> >> I am facing a problem with two dynamic libraries that implement some
> >> commands in C.
>
> >> I have library A, which depends only on system libraries (libstdc++&
> >> libSystem.B), which gets loaded ok in Tcl:
> > [...]
> >> I have then library B, which depends on A:
> > [...]
> >> So, I have loaded A through "load", but when I try to load B, I get an
> >> error:
> > [...]
> >> But libCDM.dylib has been loaded by the process, and its commands are
> >> available.
>
> >> Any idea on what may be wrong?
>
> > Curious. Looks like it is not registering the fact that the library is
> > present. (This might be a deliberate move on Apple's part to stop code
> > from getting at APIs that it shouldn't have anything to do with.)
>
> > Since both libraries are Tcl-aware, maybe you could try having one
> > export a stubbed ABI that the other uses, with the other using the
> > first through that. (The two are stitched together with a wrapper
> > round [package require].) For an example of how to build the library
> > so as to do that, see the TclOO-as-extension-package code. (Adapting
> > the consumer side should be easy enough.)
>
> > Donal.
>
> Yes, it is really strange. I am not sure that I understood the stubbed
> ABI solution you propose (the library is linked by many dlls actually,
> not all tcl-related) :-)
>
> However, looking (for many hours) on the net, led me to a deprecated
> function(!):https://developer.mozilla.org/en/Using_Dependent_Libraries_In_Extensi...
>
> There is a function named NSAddImage:http://developer.apple.com/mac/library/documentation/DeveloperTools/R...
>
> If I call this function with the shared library that the whole
> application must see, with the parameters
> NSADDIMAGE_OPTION_RETURN_ON_ERROR |
> NSADDIMAGE_OPTION_WITH_SEARCHING |
> NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME
>
> it does the obvious: the loaded shared library is visible to other
> shared libraries, as it should.
>
> Of course, the problem is that the function is already deprecated.
> So, I have to find an alternative to this :-(

Out of curiosity, is all this so different from dlopen's RTLD_GLOBAL ?

-Alex