adrg / libvlc-go

Handcrafted Go bindings for libVLC and high-level media player interface
https://pkg.go.dev/github.com/adrg/libvlc-go/v3
MIT License
437 stars 50 forks source link

Error running on Windows: libvlc.dll not found #61

Closed dmerrick closed 3 years ago

dmerrick commented 3 years ago

I have followed your wiki instructions on a fresh install of Windows.

> gcc --version
gcc (Rev5, Built by MSYS2 project) 10.2.0

> ls C:\libvlc-3.0.8.1
hrtfs  include  libvlc.dll  libvlc.lib  libvlccore.dll  libvlccore.lib  locale  lua  plugins  vlc.lib  vlccore.lib

> ls C:\libvlc-3.0.8.1\include\vlc
deprecated.h     libvlc_events.h            libvlc_media_library.h      libvlc_media_player.h         libvlc_vlm.h
libvlc.h         libvlc_media.h             libvlc_media_list.h         libvlc_renderer_discoverer.h  plugins
libvlc_dialog.h  libvlc_media_discoverer.h  libvlc_media_list_player.h  libvlc_version.h              vlc.h

> echo %PATH%
C:\Users\Dana\GolandProjects\go-1.13.15\go1.13.15\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Syst
em32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program F
iles\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\PowerShell\7\;C:\msy
s64\mingw64\bin;C:\msys64\usr\bin;C:\Users\Dana\AppData\Local\Microsoft\WindowsApps;

> echo %CGO_CFLAGS%
-IC:\libvlc-3.0.11\include

> echo %CGO_LDFLAGS%
-LC:\libvlc-3.0.11\lib

I have been switching between different versions of libvlc, libvlc-go, and go in my various attempts to get this working.

Sometimes I see:

> go build vlc-server.go
# github.com/adrg/libvlc-go/v3
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvlc
collect2.exe: error: ld returned 1 exit status

When I got past the go build step and ran the executable I got a popup that says:

The code execution cannot proceed because the libvlc.dll was not found. Reinstalling the program may fix this problem.

When I get this error I see the following in the terminal:

Process finished with exit code -1073741515 (0xC0000135)

I'm running out of things to try... any suggestions?

Thank you for maintaining this!

adrg commented 3 years ago

Hi @dmerrick. From what I can tell from the information you attached, your CGO_LDFLAGS environment variable is not pointing to the correct directory: -LC:\libvlc-3.0.11\lib instead of -LC:\libvlc-3.0.8.1. You mentioned switching between different versions of libvlc, 3.0.11 being one of them probably. However, even for that CGO_LDFLAGS would have to be -LC:\libvlc-3.0.11 (no \lib).

For 3.0.8.1

set CGO_LDFLAGS=-LC:\libvlc-3.0.8.1
set CGO_CFLAGS=-IC:\libvlc-3.0.8.1\include
go build

For 3.0.11

set CGO_LDFLAGS=-LC:\libvlc-3.0.11
set CGO_CFLAGS=-IC:\libvlc-3.0.11\include
go build

Also, please make sure you are building the executable in a Windows CMD.

dmerrick commented 3 years ago

Thanks, you're right that I mixed up some of these details. Still having trouble though:

>set CGO_LDFLAGS=-L-LC:\libvlc-3.0.11
>set CGO_CFLAGS=-I-LC:\libvlc-3.0.11\include
> go build vlc-server.go
# github.com/adrg/libvlc-go/v3
..\..\..\..\go\pkg\mod\github.com\adrg\libvlc-go\v3@v3.0.7\av.go:4:11: fatal error: vlc/vlc.h: No such file or directory
    4 | // #include <vlc/vlc.h>
      |           ^~~~~~~~~~~
compilation terminated.
>set CGO_LDFLAGS=-LC:\libvlc-3.0.8.1
>set CGO_CFLAGS=-IC:\libvlc-3.0.8.1\include
> go build vlc-server.go
# build passes, but .exe raises missing libvlc.dll error

Those are with golang v1.13.15 and libvlc-go v3.0.7

With golang v1.15.6, both versions of libvlc will go build correctly but both give the missing dll error

adrg commented 3 years ago

Sorry, there was a typo in my comment for 3.0.11:

set CGO_LDFLAGS=-LC:\libvlc-3.0.11
set CGO_CFLAGS=-IC:\libvlc-3.0.11\include
go build

So the build process succeeds for 3.0.8.1 but you still get the DLL message? That seems odd. Does it work if you copy libvlc.dll in your build directory?

adrg commented 3 years ago

You can also try adding C:\libvlc-3.0.8.1 and/or C:\libvlc-3.0.11 to your Path environment variable, in the same way you added the MSYS2 paths. Make sure to build the application in a new CMD instance after so that the environment variables are reloaded.

EDIT: you should not need to copy libvlc.dll in your build directory if you do this.

dmerrick commented 3 years ago

Amazing! Adding the libvlc dir to my path got it to build!

Now my issue is the playback window isn't showing up. On linux my app opens a window containing a playing video, but none appears on my freshly-compiled Windows binary

adrg commented 3 years ago

Hm, what's the content of the libVLC package you are using? Is it the one you added in your first post?

> ls C:\libvlc-3.0.8.1
hrtfs  include  libvlc.dll  libvlc.lib  libvlccore.dll  libvlccore.lib  locale  lua  plugins  vlc.lib  vlccore.lib

The libVLC NuGet package should contain some other directories as well, like the plugins directory. The installation directory shoud look something like this:

libvlc_installation_dir

Also, please make sure you don't specify the --no-video flag when initializing the libvlc-go package.

adrg commented 3 years ago

Oh, sorry, I see you already have the plugins directory. I somehow missed it. Is there anything the application outputs when you run it? Try adding the -vvv flag when initializing libvlc-go. Maybe that will give us a hint regarding the issue.

dmerrick commented 3 years ago

Sweet, we're getting closer. Here's the -vvv:

[h264 @ 00000275e8372560] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 00000275e8372560] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 00000275e8372560] nal_unit_type: 6, nal_ref_idc: 0
[h264 @ 00000275e8372560] nal_unit_type: 5, nal_ref_idc: 3
[00000275e84639f0] main video output error: video output creation failed
[00000275e83371e0] main decoder error: failed to create video output
[00000275e85ee990] main video output error: video output creation failed
[00000275e83371e0] main decoder error: failed to create video output
[h264 @ 00000275e8372560] Format yuv420p chosen by get_format().
[h264 @ 00000275e8372560] Reinit context to 1920x1088, pix_fmt: yuv420p
[00000275e95a2ab0] main video output error: video output creation failed
[00000275e83371e0] main decoder error: failed to create video output
[h264 @ 00000275e8372560] get_buffer() failed
[h264 @ 00000275e8372560] thread_get_buffer() failed
[h264 @ 00000275e8372560] decode_slice_header error
[h264 @ 00000275e8372560] no frame!
[h264 @ 00000275e83aa860] nal_unit_type: 1, nal_ref_idc: 2

(this repeats over and over)

dmerrick commented 3 years ago

Nevermind, I got it! I was using --vout x11, which obviously ain't gonna work on Windows.

Thank you for your quick help, and thanks again for maintaining this!

adrg commented 3 years ago

That's great! I'm glad you got it to work.

dmerrick commented 3 years ago

Couldn't've done it without you, Adrian!

If you're curious about the project, it's a 24/7 slow-tv Twitch stream with an associated chatbot.

adrg commented 3 years ago

Thank you. I'll definitely check it out! I'm actually thinking of creating a README section with projects using the package at some point. Maybe I can add an entry for your project there if that's ok.

dmerrick commented 3 years ago

Of course that'd be okay! I can add a link to this project in my README too, if I haven't already :)

adrg commented 3 years ago

@dmerrick I created an In action README section and added your project there.