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

Can gocv package OpenCV into a binary file through cgo? #1056

Open
yh4922 opened this issue Feb 21, 2023 · 13 comments
Open

Can gocv package OpenCV into a binary file through cgo? #1056

yh4922 opened this issue Feb 21, 2023 · 13 comments

Comments

@yh4922
Copy link

yh4922 commented Feb 21, 2023

There is a requirement that the project needs to be deployed on many devices, and some devices cannot even install docker and there is no way to precompile opencv

If there is a way to package opencv into a binary file at compile time, it should be a good solution to this problem

Similar to go-sqlite3

I don't know if this example is appropriate, but in short, what I want to express is this

@abhikalitra
Copy link

for deployment copy opencv libs and set LD_LIBRARY_PATH to that folder
cp -r /usr/local/lib/libopencv*.* build/${VER}/libs
export LD_LIBRARY_PATH=pwd/libs/

thats what we do for builds

@jan-bar
Copy link

jan-bar commented Apr 24, 2023

https://github.com/jan-bar/xgo/blob/master/docker/readme.md

You can try my project, I made a docker image. And completed the compilation of window under Linux, and also used cgo. gocv supports static compilation. You can prepare cross-compilation tools and use static compilation, which should be able to achieve the effect you want.

image

@yh4922
Copy link
Author

yh4922 commented Apr 24, 2023

Sure, I’d be happy to give it a try! Thank you!

@yh4922
Copy link
Author

yh4922 commented Apr 24, 2023

https://github.com/jan-bar/xgo/blob/master/docker/readme.md

You can try my project, I made a docker image. And completed the compilation of window under Linux, and also used cgo. gocv supports static compilation. You can prepare cross-compilation tools and use static compilation, which should be able to achieve the effect you want.

image

It seems to be not working well. I encountered an error when compiling gocv on the ARM platform. You can refer to my question here: #1057

@jan-bar
Copy link

jan-bar commented Apr 24, 2023

I don't have an arm-based device, and cross-compiling opencv for arm always reports an error. It seems that you need to explore it carefully. I think some libraries also need to be cross-compiled. If there is an arm-based environment, I may not have such trouble.

You can refer to the official method for cross-compilation

-DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake

https://github.com/opencv/opencv/blob/4.x/.github/workflows/arm64-build-checks.yml

@jan-bar
Copy link

jan-bar commented Apr 27, 2023

@yh4922 same problem see here:JuliaLang/julia#41613

After my unremitting efforts, I finally found that opencv cannot be compiled on the arm64 platform. Eventually there will be compilation errors

libquadmath0 not support aarch64

image

@yh4922
Copy link
Author

yh4922 commented May 8, 2023

May I ask if there is any solution? The normal compilation method works on arm64, but static compilation does not.

同样的问题看这里:朱莉娅郎/朱莉娅#41613

经过我的不懈努力,我终于发现opencv无法在arm64平台上编译。最终会出现编译错误

libquadmath0不支持 AAc64

图像

@jan-bar
Copy link

jan-bar commented May 8, 2023

@yh4922 I have tried without success,you can study further.

@yh4922
Copy link
Author

yh4922 commented May 9, 2023

Okay, thank you very much.

@yh4922 yh4922 changed the title gocv 能否通过cgo 把 opencv 打包到二进制文件中 Can gocv package OpenCV into a binary file through cgo? Aug 21, 2023
@jocemarkovacs
Copy link

jocemarkovacs commented Nov 9, 2023

I’m having a problem similar to this one, so maybe someone has already come in a solution to that.

I did a program in Go using gocv and go-face, it is working and compiling perfectly in Ubuntu. But I would like to build for Windows platform. If I try to cross-platform appear syntax errors in the code... If you take the code for Windows and try to compile, there is always a library or other that the compiler does not find or the path to the file is non-existent.

Would anyone have a path that could go to solve this problem?

PS. I have already followed the installation tutorials of dependencies, both gocv and go-face, among others.

@Klaus-Tockloth
Copy link

For me, it's also not possible to build a static binary on ARM64 (Raspberry Pi 5 with PiOS-Bookwork):

go build -v -tags static -ldflags="-extldflags=-static"
log/internal
log
gocv.io/x/gocv
klaus/openCV/hello-cv
# klaus/openCV/hello-cv
/usr/local/go/pkg/tool/linux_arm64/link: running g++ failed: exit status 1
/usr/bin/ld: cannot find -lIlmImf: No such file or directory
/usr/bin/ld: cannot find -lippiw: No such file or directory
/usr/bin/ld: cannot find -lippicv: No such file or directory
/usr/bin/ld: cannot find -lquadmath: No such file or directory
/usr/bin/ld: /usr/local/lib/libopencv_core.a(opencl_core.cpp.o): in function `opencl_check_fn(int)':
opencl_core.cpp:(.text._ZL15opencl_check_fni+0x168): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status

@yh4922
Copy link
Author

yh4922 commented Mar 11, 2024

I would like to know if this issue has received support.

@jocemarkovacs
Copy link

jocemarkovacs commented Mar 11, 2024 via email

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