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

How to build the "webcam" example for raspi os (32bit) on linux amd64 machine? #37

Open
bbasic opened this issue Dec 21, 2022 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@bbasic
Copy link

bbasic commented Dec 21, 2022

When I try to build the example in go4vl/examples/webcam directory on my machine (linux amd64) for ARM architecture I get following error:

> GOARCH=arm ./build.sh 
# github.com/vladimirvivien/go4vl/v4l2
/home/me/go/pkg/mod/github.com/vladimirvivien/go4vl@v0.0.5/v4l2/types.go:11:15: undefined: Capability
/home/me/go/pkg/mod/github.com/vladimirvivien/go4vl@v0.0.5/v4l2/types.go:12:14: undefined: IOType
/home/me/go/pkg/mod/github.com/vladimirvivien/go4vl@v0.0.5/v4l2/types.go:23:15: undefined: BufType

What I am doing wrong?
What should I do?

@vladimirvivien
Copy link
Owner

@bbasic thank you for checking out the project.
No you are not doing anything wrong.
I have ran on similar issue cross compiling from other OS (Mac OS).
This is something I am actively investigating how to fix.
As a workaround, build on your RPi if you can.

@vladimirvivien vladimirvivien self-assigned this Dec 21, 2022
@vladimirvivien vladimirvivien added the enhancement New feature or request label Dec 21, 2022
@dinobei
Copy link

dinobei commented Feb 21, 2023

I also experienced the same problem. (cross compiling from m1 macos to arm64)
So, according to your comment, I tried to build by installing golang on the target board (arm64) but the same problem occurs.

@vladimirvivien
Copy link
Owner

Hi @bbasic and @dinobei
I updated the docs for the examples so that they can be cross-compiled.
Please see instructions here

@dinobei
Copy link

dinobei commented Feb 27, 2023

Thanks for the reply.
Cross-compile method using zig was also applied.
Build succeeds in amd64 linux, but
On arm64 macos (m1), the following error occurs.

$ CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CC="zig cc -target arm-linux-musleabihf" CXX="zig c++ -target arm-linux-musleabihf" go build -o snap snap.go
# runtime/cgo
info: Usage: zig [command] [options]

Commands:

  build            Build project from build.zig
  init-exe         Initialize a `zig build` application in the cwd
  init-lib         Initialize a `zig build` library in the cwd

  ast-check        Look for simple compile errors in any set of files
  build-exe        Create executable from source or object files
  build-lib        Create library from source or object files
  build-obj        Create object from source or object files
  fmt              Reformat Zig source into canonical form
  run              Create executable and run immediately
  test             Create and run a test build
  translate-c      Convert C code to Zig code

  ar               Use Zig as a drop-in archiver
  cc               Use Zig as a drop-in C compiler
  c++              Use Zig as a drop-in C++ compiler
  dlltool          Use Zig as a drop-in dlltool.exe
  lib              Use Zig as a drop-in lib.exe
  ranlib           Use Zig as a drop-in ranlib
  objcopy          Use Zig as a drop-in objcopy

  env              Print lib path, std path, cache directory, and version
  help             Print this help and exit
  libc             Display native libc paths file or validate one
  targets          List available compilation targets
  version          Print version number and exit
  zen              Print Zen of Zig and exit

General Options:

  -h, --help       Print command-specific usage

error: unknown command: -E

Or is this a zig issue?

@vladimirvivien
Copy link
Owner

@dinobei It may be that you are using Go version older than 1.18. If that is the case, you can either upgrade to the latest Go version or follow instructions here (toward bottom of post) for older Go version.

@y4roc
Copy link

y4roc commented Mar 7, 2023

I followed you instructions. But I get some errors:

vendor/github.com/vladimirvivien/go4vl/v4l2/control_values.go:115:32: could not determine kind of name for C.V4L2_COLORFX_SET_RGB
vendor/github.com/vladimirvivien/go4vl/v4l2/control_values.go:76:41: could not determine kind of name for C.V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR
vendor/github.com/vladimirvivien/go4vl/v4l2/control_values.go:77:41: could not determine kind of name for C.V4L2_CTRL_TYPE_VP9_FRAME

I looked for this constants in v4l2 and they are existing there, but the go compiler doesn't find them.

I'm using go1.20.1 darwin/arm64 and want to compile with this command CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CC="zig cc -target arm-linux-musleabihf" CXX="zig c++ -target arm-linux-musleabihf" go build

@vladimirvivien
Copy link
Owner

Hi @y4roc
Thanks for your interest in go4vl.

You only need to use zig if you are cross-compiling the code (from a non-linux machine). If you are building on Linux, please follow the on-device build.

If you are cross-compiling (say from MacOS), make sure you have the latest zig language compiler installed on your local machine. Then follow the instructions.

Hope that helps.

@dronasys
Copy link

If you are vendoring (go mod) in this package, the 'include' directory (with the C headers) will be missing from the vendor directory.
So even if you use zig cross compiler, you might see this error (happens only during vendoring)

To fix, manually copy the include directory from this repo, to vendor/github.com/vladimirvivien/go4vl/.

Note, when you checkout this project and compile directly, you will not see this error, since the include folder is present.

@vladimirvivien
Copy link
Owner

Hi, apologies for the late follow.
I want to clarify that vendoring is not required for building the code.
You can try to use vendor approach, but I usually build without vendoring.
Please reply here if that works for you.

@dronasys
Copy link

Hi, apologies for the late follow.
I want to clarify that vendoring is not required for building the code.
You can try to use vendor approach, but I usually build without vendoring.
Please reply here if that works for you.

Hi @vladimirvivien , when compiling as standalone, this project works fine. But most of the devs, would want to use this as a package or library. And the errors reported above, happen when devs vendor in the code.

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

No branches or pull requests

5 participants