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
433 stars 50 forks source link

Cannot build BaseExample #74

Closed masseelch closed 3 years ago

masseelch commented 3 years ago

I tried to run this but the build fails with

# command-line-arguments
cmd/client/main.go:34:12: undefined: vlc.Init
cmd/client/main.go:37:8: undefined: vlc.Release
cmd/client/main.go:40:17: undefined: vlc.NewPlayer
» gcc --version
gcc (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
» ls /usr/lib | grep libvlc
libvlccore.so
libvlccore.so.9
libvlccore.so.9.0.0
libvlc.so
libvlc.so.5
libvlc.so.5.6.0

I use Kernel 5.4.116-1-MANJARO.

masseelch commented 3 years ago

Nervermind. I had an issue with my go-path. I am sorry! Everything works like it should.

masseelch commented 3 years ago

Me again. The issue still is there when trying to cross compile for arm. It does happen for all version (5,6,7).

adrg commented 3 years ago

Hi @masseelch. I haven't tried cross-compiling for ARM. However, you will probably have to cross compile libvlc itself first and I'm not sure that's such an easy task.

As for cross-compiling a Go application using libvlc-go, you will need to install an ARM compiler like arm-linux-gnueabi-gcc or arm-linux-gnueabi-g++-7 (which you'll probably already have because you'll need it for compiling libvlc) and then do something like:

CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build
masseelch commented 3 years ago

In my case I want to build for raspberry pi and there is a precombiled version of libvlc on the latest raspberry pi os i can use.

I however did just now learn about cgo. I will try to go down that road an report. Thanks for the directions!

adrg commented 3 years ago

No problem. Let me know how it goes.

masseelch commented 3 years ago

Progress so far:

I downloaded the official crosscompiling tools and linked the header files and library already present on the latest raspberrypios buster.

The build itself is succeeding i think, but there are linker errors i have to resolve yet.

» CPATH=/workspace/libvlc-go/include LD_LIBRARY_PATH=/workspace/libvlc-go/lib CC=/workspace/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build main.go
# github.com/adrg/libvlc-go/v3
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
/home/jcl/Code/display/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lvlc
collect2: error: ld returned 1 exit status

If you have any ideas I'd appreciate.

adrg commented 3 years ago

Is /workspace/libvlc-go/lib the location of the libvlc.so shared library compiled for ARM? If so, you can try adding CGO_LDFLAGS="-L/workspace/libvlc-go/lib" in your build command:

CPATH=/workspace/libvlc-go/include CGO_LDFLAGS="-L/workspace/libvlc-go/lib" LD_LIBRARY_PATH=/workspace/libvlc-go/lib CC=/workspace/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build main.go
masseelch commented 3 years ago

Yes, this resolved the linker issue but got me a new one.

warning: libvlccore.so.9, needed by /workspace/libvlc-go/lib/libvlc.so, not found

ibvlccore.so.9 is present in the same dir as libvlc.so. I look at that tomorrow. Thanks a lot for your help!

The same happens when i tried building with dockercross.

masseelch commented 3 years ago

CGO_LDFLAGS="-Wl,-L/workspace/libvlc-go/lib,-rpath=/workspace/libvlc-go/lib" solved that issue but know it complains about missing libidn.so.11 and libdbus-1.so.3 ...

masseelch commented 3 years ago

After adding in all required libraries I detected, that the tools i mentioned above had been compiled with GLIBC@2.23 which are no longer suitable for gcc7 and above. However this repo had the correct toolchain and with it and rpath-link everything works (at least on RPI3, didnt test on RPI4 yet).

Thank you for your help.

For anyone landing here:

CPATH=/workspace/libvlc-go/include CC=/opt/cross-pi-gcc/bin/arm-linux-gnueabihf-gcc CGO_LDFLAGS="-Wl,-L/workspace/libvlc-go/lib,-rpath-link=/workspace/libvlc-go/lib" CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build main.go