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

building a static binary with gocv/opencv:4.9.0-static fails #1169

Open
mihaiav opened this issue Apr 19, 2024 · 4 comments
Open

building a static binary with gocv/opencv:4.9.0-static fails #1169

mihaiav opened this issue Apr 19, 2024 · 4 comments

Comments

@mihaiav
Copy link

mihaiav commented Apr 19, 2024

Building a Go app with gocv/opencv:4.9.0-static docker image fails.

Description

I'm trying to build a static go binary using gocv/opencv:4.9.0-static as base. Unfortunately the go build command fails. Is this a known bug? Does it require an additional configuration to make it compile? Given gocv is already shipped in the docker image I expected it to just work.

Steps to Reproduce

I'm a Dockerfile to build the app and later run it as part of a web service. The docker file is pretty simple. Here is a bit more reduced:

FROM gocv/opencv:4.9.0-static as golang ... RUN go build -ldflags="-extldflags=-static" -o main
It throws a bunch of errors such below. log.txt

/usr/local/go/pkg/tool/linux_amd64/link: running g++ failed: exit status 1
/usr/bin/ld: /tmp/go-link-1938547386/000056.o: in function mygetgrouplist': /usr/bin/ld: /usr/local/lib/libopencv_dnn.a(types.pb.cc.o): in function _GLOBAL__sub_I.00102_types.pb.cc':
types.pb.cc:(.text.startup._GLOBAL__sub_I.00102_types.pb.cc+0xf): undefined reference to google::protobuf::internal::AddDescriptorsRunner::AddDescriptorsRunner(google::protobuf::internal::DescriptorTable const*)' /usr/bin/ld: $WORK/b001/exe/a.out: hidden symbol opj_read_header' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
`

Your Environment

`

  • Operating System and version:
    Google cloud run E2 standard 4 (4 vcpu, 16 gb ram)
    * OpenCV version used:
    Docker repo gocv/opencv:4.9.0-static
  • How did you install OpenCV?
    I've got it preinstalled using the docker repo : gocv/opencv:4.9.0-static
  • GoCV version used:
    I use go modules withgocv.io/x/gocv v0.36.1, vendored as well.
  • Go version:
    docker based gocv/opencv:4.9.0-static which I believe has Go go1.22.0
  • Did you run the env.sh or env.cmd script before trying to go run or go build?
    Yes, it said This script is no longer necessary and has been deprecated. See the Custom Environment section of the README if you need to customize your environment.
@lujihong
Copy link

lujihong commented May 7, 2024

It happened to me too, I compiled and installed a static version of opencv and it also reported a bunch of errors when compiling.

I've taken a random snippet of the error:

C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libopencv_dnn490.a(attr_value.pb.cc.obj):attr_value.pb.cc:(.text$_ZN6google8protobuf8i
nternal8MapFieldIN17opencv_tensorflow31NameAttrList_AttrEntry_DoNotUseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS3_9AttrValueELNS1_14WireFormatLite9FieldTypeE9ELSD_11E
E14DeleteMapValueERKNS0_6MapKeyE[_ZN6google8protobuf8internal8MapFieldIN17opencv_tensorflow31NameAttrList_AttrEntry_DoNotUseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS
3_9AttrValueELNS1_14WireFormatLite9FieldTypeE9ELSD_11EE14DeleteMapValueERKNS0_6MapKeyE]+0x66b): undefined reference to `google::protobuf::internal::LogMessage::operator<<(char const*)'

@neilyoung
Copy link

It not even works outside docker...

@ansoni-san
Copy link

ansoni-san commented Jun 20, 2024

I have been doing static builds of gocv for years and it runs fine. We don't use the docker image though.

Is this a new issue in 4.9.0? Were the builds working for you before or is this your first time doing a static build?

@nuzz
Copy link

nuzz commented Jul 24, 2024

There seems to be quite a few issues surrounding confusing failures while attempting to build a statically linked go binary that involves gocv. Is there a working example of a multistage Dockerfile that works to demonstrate this?

The docs allude to this being possible however it doesn't seem like anyone has this working properly. I'm attempting this with gocv/opencv:4.10.0-static. The goal would be to copy the single binary into a minimalistic container like chainguard/static:latest.

Alternatively is there a good example of how to ship a gocv based golang binary that's dynamically linked and copy the necessary libs into a minimal container to run? The goal here is to avoid shipping a multi gigabyte container in order to run gocv workloads on kubernetes.

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

5 participants