Loading shared libraries in macOS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Loading shared libraries in macOS

Aleksid
Why is ffmpeg looking for shared libraries in a folder where I compiled
FFmpeg sources on macOS Catalina?

Source code of FFmpeg is located in /usr/local/Cellar/ffmpeg

./configure --enable-shared --extra-cflags="-fno-stack-check" --enable-gpl
 --enable-version3 --enable-pthreads --enable-nonfree
make

Then I put all compiled shared libraries and small ffmpeg binary file to a
folder:  /Users/aleks/test/

I call ./ffmpeg

Library not loaded: /usr/local/Cellar/ffmpeg/lib/libavdevice.58.dylib
Referenced from: /Users/aleks/test/./ffmpeg
Reason: image not found

Why? All shared libraries are located in the same folder as ffmpeg
executable:  /Users/aleks/test/
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Loading shared libraries in macOS

Carl Eugen Hoyos-2



> Am 12.08.2020 um 09:14 schrieb Aleksid <[hidden email]>:
>
> Why is ffmpeg looking for shared libraries in a folder where I compiled
> FFmpeg sources on macOS Catalina?
>
> Source code of FFmpeg is located in /usr/local/Cellar/ffmpeg
>
> ./configure --enable-shared --extra-cflags="-fno-stack-check" --enable-gpl
> --enable-version3 --enable-pthreads --enable-nonfree

The last two options only have disadvantages for you, no advantages.

Why are you not using the --prefix option?

> make
>
> Then I put all compiled shared libraries and small ffmpeg binary file to a
> folder:  /Users/aleks/test/

How do you “put” them there?

I always use static libraries because I want to “put” my binaries where I decide to put them at any time. If you choose to use dynamic FFmpeg libraries, you lose this freedom. I don’t think this is related to FFmpeg in any way.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Loading shared libraries in macOS

Reindl Harald
In reply to this post by Aleksid


Am 12.08.20 um 09:14 schrieb Aleksid:

> Why is ffmpeg looking for shared libraries in a folder where I compiled
> FFmpeg sources on macOS Catalina?
>
> Source code of FFmpeg is located in /usr/local/Cellar/ffmpeg
>
> ./configure --enable-shared --extra-cflags="-fno-stack-check" --enable-gpl
>  --enable-version3 --enable-pthreads --enable-nonfree
> make
>
> Then I put all compiled shared libraries and small ffmpeg binary file to a
> folder:  /Users/aleks/test/
>
> I call ./ffmpeg
>
> Library not loaded: /usr/local/Cellar/ffmpeg/lib/libavdevice.58.dylib
> Referenced from: /Users/aleks/test/./ffmpeg
> Reason: image not found
>
> Why? All shared libraries are located in the same folder as ffmpeg
> executable:  /Users/aleks/test/

becasue that's how shared libraries are working on the OS level given
that you are not using the dumb microsoft windows loading and starting
everything from the current working directory including each and every
exploit

either build a static binary or think about the install location
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Loading shared libraries in macOS

Aleksid
In reply to this post by Carl Eugen Hoyos-2
>> Then I put all compiled shared libraries and small ffmpeg binary file to
a
>> folder:  /Users/aleks/test/

> How do you “put” them there?

> I always use static libraries because I want to “put” my binaries where I
decide to put them at any time. If > you choose to use dynamic FFmpeg
libraries, you lose this freedom. I don’t think this is related to
> FFmpeg in any way.

Carl,

Thanks for your reply!

I plan to include FFmpeg binaries, my app and FFmpeg shared libraries into
my application bundle for macOS.

Is it technically possible to compile ffmpeg or my app to load shared
libraries on macOS from the current folder?

I wrote a test app and I tried to dynamically load FFmpeg shared libraries
from the current folder using absolute file path to each dylib file. First
dylib loads OK, but any next dylib also fails to load.

They can be loaded only if I use --prefix=/usr/local/Cellar/ffmpeg and then
put dylibs into  /usr/local/Cellar/ffmpeg/libs folder.

I understand that it is correct in a world of Unix systems. But I would
prefer to keep dylibs locally, without copying into the system folder.

Aleks,
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Loading shared libraries in macOS

Reindl Harald


Am 12.08.20 um 13:52 schrieb Aleksid:

>>> Then I put all compiled shared libraries and small ffmpeg binary file to
> a
>>> folder:  /Users/aleks/test/
>
>> How do you “put” them there?
>
>> I always use static libraries because I want to “put” my binaries where I
> decide to put them at any time. If > you choose to use dynamic FFmpeg
> libraries, you lose this freedom. I don’t think this is related to
>> FFmpeg in any way.
>
> Carl,
>
> Thanks for your reply!
>
> I plan to include FFmpeg binaries, my app and FFmpeg shared libraries into
> my application bundle for macOS.
>
> Is it technically possible to compile ffmpeg or my app to load shared
> libraries on macOS from the current folder?
>
> I wrote a test app and I tried to dynamically load FFmpeg shared libraries
> from the current folder using absolute file path to each dylib file. First
> dylib loads OK, but any next dylib also fails to load.
>
> They can be loaded only if I use --prefix=/usr/local/Cellar/ffmpeg and then
> put dylibs into  /usr/local/Cellar/ffmpeg/libs folder.
>
> I understand that it is correct in a world of Unix systems. But I would
> prefer to keep dylibs locally, without copying into the system folder

why in the world don't you then just use "--enable-static" to avoid the
shared libraries when they are supposed to be in the same folder and
bundle anyways?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Loading shared libraries in macOS

Aleksid
> why in the world don't you then just use "--enable-static" to avoid the
> shared libraries when they are supposed to be in the same folder and
> bundle anyways?

Hi Harald,

I need to link FFmpeg the shared libraries in my app and also use ffmpeg
executable. Both programs should link dylibs. So impossible to use static
linking.

Well, I can copy FFmpeg dylibs to /usr/local/bin. But FFmpeg version 4.1,
4.2, 4.3 use the same file names, for example libavcodec.58.dylib. What
should I do if  /usr/local/bin already contains dylibs with these file
names? How can I guess about version 4.1, 4.2 or 4.3? If another program
will rewrite these dylibs, and I'll get an older version of FFmpeg libs?
It's another kind of dylib hell.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Loading shared libraries in macOS

Moritz Barsnick
On Wed, Aug 12, 2020 at 18:01:54 +0300, Aleksid wrote:
> I need to link FFmpeg the shared libraries in my app and also use ffmpeg
> executable. Both programs should link dylibs. So impossible to use static
> linking.

It's not specifically an ffmpeg question, but perhaps your ffmpeg
libav* libraries are the first ones you need to "bundle".

I come from a world of ELF binary format, but I found out that you can
achieve the same thing with Mac OS.

The binary program which references the dynlibs can be provided with a
"run path", usually called RPATH, RUN_PATH, LC_RPATH or the likes,
telling the program loader where to (additionally) search for the
required dependent dynlibs.

On ELF systems, you can provide an RPATH with a literal "$ORIGIN"
component, telling the loader to look into the same directory as the
program. You can set/amend the RPATH during the linking process, or
change it using tools such als "patchelf", "chrpath", or possibly
something from elfutils.

On Mac OS, I figured out that the corresponding command for its binary
format is "install_name_tool". Here's some info explaining its uses:
https://medium.com/@donblas/fun-with-rpath-otool-and-install-name-tool-e3e41ae86172

And a thread touching this is here, with this particular answer:
https://stackoverflow.com/a/44796519

Good luck! (I don't have Mac OS.)

> names? How can I guess about version 4.1, 4.2 or 4.3? If another program
> will rewrite these dylibs, and I'll get an older version of FFmpeg libs?
> It's another kind of dylib hell.

You are supposed to have good control of which programs write stuff
destroying your efforts. ;-)

Cheers,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Loading shared libraries in macOS

Carl Zwanzig
In reply to this post by Aleksid
On 8/12/2020 4:52 AM, Aleksid wrote:
> They can be loaded only if I use --prefix=/usr/local/Cellar/ffmpeg and then
> put dylibs into  /usr/local/Cellar/ffmpeg/libs folder.

Then do that, it's what --prefix is for.

> I understand that it is correct in a world of Unix systems. But I would
> prefer to keep dylibs locally, without copying into the system folder.

MacOS is in many ways a *nix system.


This is not an ffmpeg question, this is about how macos handles libraries.
You'll probably get better information if you learn more about that.

On 8/12/2020 8:01 AM, Aleksid wrote:
> Well, I can copy FFmpeg dylibs to /usr/local/bin. But FFmpeg version
> 4.1, 4.2, 4.3 use the same file names, for example libavcodec.58.dylib.

Yes, that's correct.

> What should I do if  /usr/local/bin already contains dylibs with these
> file names? How can I guess about version 4.1, 4.2 or 4.3? If another
> program will rewrite these dylibs, and I'll get an older version of
> FFmpeg libs? It's another kind of dylib hell.
The whole point of shared libraries is that many applications can use them.
If you want only your app and your build of ffmpeg to use these particular
lib, make a subdir and put them in there.

z!
(who goes by 'z', not 'Carl')
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Loading shared libraries in macOS

Aleksid
In reply to this post by Moritz Barsnick
 > It's not specifically an ffmpeg question, but perhaps your ffmpeg
> libav* libraries are the first ones you need to "bundle".

> I come from a world of ELF binary format, but I found out that you can
> achieve the same thing with Mac OS.
> ...

Moritz,

Many thanks for your idea! I'll learn more about this format.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".