"Cross-issue" of GoCV and Raylib-Go compatibility
Simultaneous use of the GoCV and Raylib-Go packages turns out to be impossible. Here is an example of non-working code:
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
cv "gocv.io/x/gocv"
)
const SELECTOR int = 2
func main() {
switch SELECTOR {
case 1:
webcam, _ := cv.VideoCaptureDevice(0)
window := cv.NewWindow("Hello")
img := cv.NewMat()
for {
webcam.Read(&img)
window.IMShow(img)
window.WaitKey(1)
}
case 2:
rl.InitWindow(800, 450, "raylib [core] example - basic window")
defer rl.CloseWindow()
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
rl.EndDrawing()
}
}
}
go run . leads to an error:
/usr/lib/go-1.24/pkg/tool/linux_amd64/link: running g++ failed: exit status 1
/usr/bin/g++ -m64 -s -Wl,--build-id=0x67f0bdf111b087f0932b71b8eb36a8ba6b5f8dae -o $WORK/b001/exe/arachis -Wl,--export-dynamic-symbol=_cgo_panic -Wl,--export-dynamic-symbol=_cgo_topofstack -Wl,--export-dynamic-symbol=crosscall2 -Wl,--export-dynamic-symbol=go_onmouse_dispatcher -Wl,--export-dynamic-symbol=internalAudioMixedProcessorGo -Wl,--export-dynamic-symbol=internalAudioStreamCallbackGo -Wl,--export-dynamic-symbol=internalTraceLogCallbackGo -Wl,--compress-debug-sections=zlib /tmp/go-link-2702358368/go.o /tmp/go-link-2702358368/000000.o /tmp/go-link-2702358368/000001.o /tmp/go-link-2702358368/000002.o /tmp/go-link-2702358368/000003.o /tmp/go-link-2702358368/000004.o /tmp/go-link-2702358368/000005.o /tmp/go-link-2702358368/000006.o /tmp/go-link-2702358368/000007.o /tmp/go-link-2702358368/000008.o /tmp/go-link-2702358368/000009.o /tmp/go-link-2702358368/000010.o /tmp/go-link-2702358368/000011.o /tmp/go-link-2702358368/000012.o /tmp/go-link-2702358368/000013.o /tmp/go-link-2702358368/000014.o /tmp/go-link-2702358368/000015.o /tmp/go-link-2702358368/000016.o /tmp/go-link-2702358368/000017.o /tmp/go-link-2702358368/000018.o /tmp/go-link-2702358368/000019.o /tmp/go-link-2702358368/000020.o /tmp/go-link-2702358368/000021.o /tmp/go-link-2702358368/000022.o /tmp/go-link-2702358368/000023.o /tmp/go-link-2702358368/000024.o /tmp/go-link-2702358368/000025.o /tmp/go-link-2702358368/000026.o /tmp/go-link-2702358368/000027.o /tmp/go-link-2702358368/000028.o /tmp/go-link-2702358368/000029.o /tmp/go-link-2702358368/000030.o /tmp/go-link-2702358368/000031.o /tmp/go-link-2702358368/000032.o /tmp/go-link-2702358368/000033.o /tmp/go-link-2702358368/000034.o /tmp/go-link-2702358368/000035.o /tmp/go-link-2702358368/000036.o /tmp/go-link-2702358368/000037.o /tmp/go-link-2702358368/000038.o /tmp/go-link-2702358368/000039.o /tmp/go-link-2702358368/000040.o /tmp/go-link-2702358368/000041.o /tmp/go-link-2702358368/000042.o /tmp/go-link-2702358368/000043.o /tmp/go-link-2702358368/000044.o /tmp/go-link-2702358368/000045.o /tmp/go-link-2702358368/000046.o /tmp/go-link-2702358368/000047.o /tmp/go-link-2702358368/000048.o /tmp/go-link-2702358368/000049.o /tmp/go-link-2702358368/000050.o /tmp/go-link-2702358368/000051.o /tmp/go-link-2702358368/000052.o /tmp/go-link-2702358368/000053.o /tmp/go-link-2702358368/000054.o /tmp/go-link-2702358368/000055.o /tmp/go-link-2702358368/000056.o /tmp/go-link-2702358368/000057.o /tmp/go-link-2702358368/000058.o /tmp/go-link-2702358368/000059.o /tmp/go-link-2702358368/000060.o /tmp/go-link-2702358368/000061.o /tmp/go-link-2702358368/000062.o /tmp/go-link-2702358368/000063.o /tmp/go-link-2702358368/000064.o /tmp/go-link-2702358368/000065.o /tmp/go-link-2702358368/000066.o /tmp/go-link-2702358368/000067.o /tmp/go-link-2702358368/000068.o /tmp/go-link-2702358368/000069.o /tmp/go-link-2702358368/000070.o /tmp/go-link-2702358368/000071.o /tmp/go-link-2702358368/000072.o /tmp/go-link-2702358368/000073.o /tmp/go-link-2702358368/000074.o -O2 -g -lm -pthread -ldl -lrt -lxkbcommon -lwayland-client -lwayland-cursor -lwayland-egl -lGL -O2 -g -L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_signal -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_dnn -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core -O2 -g -lpthread -no-pie
/usr/bin/ld: /tmp/go-link-2702358368/000052.o: in function `Remap':
/home/if10else/go/pkg/mod/gocv.io/x/[email protected]/imgproc.cpp:1089: multiple definition of `Remap'; /tmp/go-link-2702358368/000016.o:/home/if10else/go/pkg/mod/github.com/gen2brain/raylib-go/[email protected]/raymath.h:206: first defined here
An attempt to change the name of the Remap functions as in imgproc.cpp and in raymath.h leads to a GTK error:
INFO: Initializing raylib 5.5
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO: > rcore:..... loaded (mandatory)
INFO: > rlgl:...... loaded (mandatory)
INFO: > rshapes:... loaded (optional)
INFO: > rtextures:. loaded (optional)
INFO: > rtext:..... loaded (optional)
INFO: > rmodels:... loaded (optional)
INFO: > raudio:.... loaded (optional)
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: cannot register existing type 'GtkWidget'
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: cannot add class private field to invalid type '<invalid>'
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: cannot add private field to invalid (non-instantiatable) type '<invalid>'
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: cannot register existing type 'GtkBuildable'
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: g_type_interface_add_prerequisite: assertion 'G_TYPE_IS_INTERFACE (interface_type)' failed
(arachis:170875): GLib-CRITICAL **: 20:06:16.129: g_once_init_leave: assertion 'result != 0' failed
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: g_type_register_static: assertion 'parent_type > 0' failed
(arachis:170875): GLib-GObject-CRITICAL **: 20:06:16.129: cannot add private field to invalid (non-instantiatable) type '<invalid>'
OS: 6.12.48+deb13-amd64 (64-bit) Go version: 1.24.4 GoCV version: v0.42.0 Raylib-Go version: v0.55.1
How is GTK even related to all this? Anyway, that is a known issue when you combine several CGO libraries that all include their own source or bundled libraries and do not use external library linking (e.g., see https://github.com/gen2brain/go-fitz/issues/93). And why is it more related to raylib than to GoCV? :)
How is GTK even related to all this? I don't know; I just showed what the compiler/program gave me.
And why is it more related to raylib than to GoCV? I now think I asked some stupid question; I'm sorry if that is. I created the same issue in GoCV, because it seemed to me that it was equally related to Raylib and GoCV.
Anyway, thank you for link to issue on a similar problem.
It is important to find out how GTK is related; you cannot combine its main loop with raylib just like that (if at all). OpenCV may have some optional tools built with GTK. You should check how you compile OpenCV, with what options, etc. Last time I tried to compile OpenCV for GoCV, I had a hard time. With version 2, it was very easy. GoCV expects you to compile in the exact way they imagine it to work. There are no build tags to disable features or similar. Getting distro package to work is impossible.