I can't dynamically link to libvlc.dylib on macOS, while on Windows it works great

This forum is about all development around libVLC.
alex3333
New Cone
New Cone
Posts: 1
Joined: 27 Aug 2018 10:22

I can't dynamically link to libvlc.dylib on macOS, while on Windows it works great

Postby alex3333 » 27 Aug 2018 10:36

Hello,

I have very simple code that loads libvlc at runtime and plays an mp4 file:

Code: Select all

void* load_fn(char* func) { void *res=dlsym(vlc_lib, func); if (!res) exit(1); return res; } int main() { char* path = "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib"; // libvlc.dll on Windows vlc_lib = dlopen(path, RTLD_LAZY); if (!vlc_lib) { printf("dl not loaded: %s\n", path); exit(1); } _libvlc_new=load_fn("libvlc_new"); _libvlc_media_new_location=load_fn("libvlc_media_new_location"); // a couple of other necessary functions are loaded // ..... vlc = _libvlc_new(0, 0); libvlc_media_t *m = _libvlc_media_new_path (vlc, "video.mp4"); mp = _libvlc_media_player_new_from_media (m); _libvlc_media_release (m); _libvlc_media_player_set_nsobject (mp, ns_video_view); // on Windows I call set_hwnd() _libvlc_media_player_play (mp); }

On Windows it works like a charm. But on macOS I get a crash in libvlc_media_player_new_from_media:

Code: Select all

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x28) frame #0: 0x000000010d610a7d libvlccore.dylib`config_GetPsz + 61 libvlccore.dylib`config_GetPsz: -> 0x10d610a7d <+61>: mov rdi, qword ptr [rbx + 0x28] 0x10d610a81 <+65>: test rdi, rdi 0x10d610a84 <+68>: je 0x10d610a90 ; <+80> 0x10d610a86 <+70>: call 0x10d6998a8 ; symbol stub for: strdup (lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x28) * frame #0: 0x000000010d610a7d libvlccore.dylib`config_GetPsz + 61 frame #1: 0x000000010d67d3c7 libvlccore.dylib`var_Inherit + 247 frame #2: 0x000000010d67d232 libvlccore.dylib`var_Create + 354 frame #3: 0x000000010d4d727c libvlc.dylib`libvlc_media_player_new + 316 frame #4: 0x000000010d4d7be0 libvlc.dylib`libvlc_media_player_new_from_media + 16
I tried the latest stable release and the most recent git build.

I had to modify the library file because of macOS @rpath shenanigans:

Code: Select all

install_name_tool -change @rpath/libvlccore.dylib /Applications/VLC.app/Contents/MacOS/lib/libvlccore.dylib /Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib
otherwise it wouldn't load at all.

Does any one have experience with linking to libvlc.dylib?

Thanks a lot

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: I can't dynamically link to libvlc.dylib on macOS, while on Windows it works great

Postby Jean-Baptiste Kempf » 30 Aug 2018 09:57

That's currently expected with macOS @rpath mess.

Use VLCKit or find a way to modify the rpath so it works in both VLC and linking to it (and share it with us :D)
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mfkl
Developer
Developer
Posts: 739
Joined: 13 Jun 2017 10:41

Re: I can't dynamically link to libvlc.dylib on macOS, while on Windows it works great

Postby mfkl » 30 Aug 2018 14:29

Related https://github.com/xamarin/xamarin-macios/issues/4416, might give you some insight.

Good luck
https://mfkl.github.io


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 32 guests