Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build basic player example #105

Closed
stevstrong opened this issue May 26, 2023 · 13 comments
Closed

Cannot build basic player example #105

stevstrong opened this issue May 26, 2023 · 13 comments

Comments

@stevstrong
Copy link

stevstrong commented May 26, 2023

Hi,

as also posted here, the build command for basic player example outputs on Win10 and Debian 11:

# command-line-arguments
.\player.go:12:16: undefined: vlc.Init
.\player.go:15:12: undefined: vlc.Release
.\player.go:18:21: undefined: vlc.NewPlayer

Any idea what I am missing?

@adrg
Copy link
Owner

adrg commented May 26, 2023

Hi @stevstrong,

It looks like you don't have the libvlc-go package locally. It's as if you don't have a Go module for your project.

Go to the directory with the source code for the example.

go mod init main
go mod tidy

Then you should be able to build the project.

go build
./main

@stevstrong
Copy link
Author

stevstrong commented Jun 6, 2023

Thanks, sorry for the late reply, but it is still not ok.

What I did:

  • deleted existing mod file
  • go mod init player.go (this is the name of the file)

reply:

go: creating new go.mod: module player.go
go: to add module requirements and sums:
        go mod tidy
  • go mod tidy

reply:

go: finding module for package github.com/adrg/libvlc-go/v3
go: found github.com/adrg/libvlc-go/v3 in github.com/adrg/libvlc-go/v3 v3.1.5

At this point this is the content of the go.mod file:

module player.go

go 1.20

require github.com/adrg/libvlc-go/v3 v3.1.5

Then:

  • go build player.go

reply:

# command-line-arguments
.\player.go:12:16: undefined: vlc.Init
.\player.go:15:12: undefined: vlc.Release
.\player.go:18:21: undefined: vlc.NewPlayer

I think I am still missing something but cannot figure out what...
Any ideas?

### EDIT
I tried to rename the file to main.go, deleted mod file, and entered the commands exactly as you indicated.
The result was very similar:

# main
.\main.go:12:16: undefined: vlc.Init
.\main.go:15:12: undefined: vlc.Release
.\main.go:18:21: undefined: vlc.NewPlayer

@adrg
Copy link
Owner

adrg commented Jun 6, 2023

go mod init player.go (this is the name of the file)

You should not call the module the same as your file because the name of the executable generated after build will be called that as well and it will effectively replace your source file. The name of the module can be anything (player, main, etc.).

I think you mentioned you tried building on Linux as well. I just updated my go version to 1.20 to match yours and made a quick test. This works assuming you have curl and libvlc-dev installed (I'm on Ubuntu for reference).

Here are the exact steps:

mkdir player
cd player
curl "https://raw.githubusercontent.com/adrg/libvlc-go-examples/master/v3/player/player.go" -o main.go
go mod init main
go mod tidy
go build
./main

Assuming this worked, the project can be moved exactly as is on Windows and it should work there as well.

@stevstrong
Copy link
Author

stevstrong commented Jun 6, 2023

does the path where the source code is compared to GOPATH matter?

Because funnily VS code also points those functions as "undefined".

@adrg
Copy link
Owner

adrg commented Jun 6, 2023

does the path where the source code is compared to GOPATH matter?

No, when using go modules, which is the default at this point, $GOPATH should not matter.

Did you get the chance to try building on Linux, using the steps in my previous response?

@stevstrong
Copy link
Author

On Linux go build fails with the same message as on Windows.
What settings am I missing? Some path is not correct?

@adrg
Copy link
Owner

adrg commented Jun 7, 2023

I'm not sure. There must be something weird going on with your setup. Can you post the output of go env from your Linux machine here?

One thing I noticed from your Windows environment is that the CGO_ENABLED environment variable is set to 0. It should be set to 1. You could try that and attempt building the project again.

@stevstrong
Copy link
Author

stevstrong commented Jun 7, 2023

I did on Windows:

go env -w CGO_ENABLED=1

and retried build with this output:

# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%

Strange that now VS Code does not show me any error anymore

@adrg
Copy link
Owner

adrg commented Jun 7, 2023

Alright, so that was the problem.

Now you can follow the instructions on the wiki in order to install the prerequisites:
https://github.com/adrg/libvlc-go/wiki/Install-on-Windows

@stevstrong
Copy link
Author

Ah, I somehow overlooked this step on Win. I will try it and post here the result.

I also have to look why it does not work on Linux, I think the prerequisites were loaded there already.

@adrg
Copy link
Owner

adrg commented Jun 7, 2023

I also have to look why it does not work on Linux, I think the prerequisites were loaded there already.

Most likely CGO_ENABLED enabled is set to 0 for some reason on Linux as well which is strange because if I remember correctly, the default is 1. In any case, set it to 1 there as well and it should work fine.

@stevstrong
Copy link
Author

stevstrong commented Jun 16, 2023

I acknowledge, on Linux the CGO_ENABLED flag was also set to 0.
I think this flag is set at install time because GCC was not recognized (not installed). Maybe because I have there a minimal Debian distribution.

After I ran:
sudo apt-get install build-essential
the build worked like a charm!

Maybe it makes sense to extend the read.me with this information to help other users like me.
Thanks anyway for the support and the great work!

@livrasand
Copy link

livrasand commented Oct 15, 2023

Hello, I have a similar problem, but it gives me this error:

# github.com/adrg/libvlc-go/v2
..\..\..\go\pkg\mod\github.com\adrg\libvlc-go\v2@v2.1.4\av.go:4:11: fatal error: vlc/vlc.h: No such file or directory
     4 | // #include <vlc/vlc.h>
       | ^~~~~~~~~~~
compilation terminated.

I have all the prerequisites installed, I have the latest version of Go and I am using Windows.

What I can do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants