OpenCV Mixing Compilers (Big Project Compound issues)

Alright this is a big one, my apologies for the size.

I am dealing with a rather large and extremely complex issue that is likely going to result in some kind of debate about direction.

I am in a corporate environment, dealing with a roughly 3.5 year codebase in C++ to use OpenCV and Nvidia CUDA for AI. It is a full suite type of application with a full IDE with dockable windows, custom GKT widgets, and a laundry list of link libs.

I am cornered because when we started, Windows was 100% out of the question. We were to ship linux appliances. Now things changed and after months of trying to get ported to windows, we are stuck with a bad Catch-22 of dependency hell.

In a nutshell, Nvidia Cuda requires Visual Studio, but Visual Studio cannot build various GTK3 libraries such as (gtk3, gtkmm, gdl, gdlmm, cairo, cairomm, sourceviewmm3)

My AI training application I broke out into a separate binary, I aim to build it with visual studio + Cuda + OpenCV (with cuda) and then built the rest of the application with MinGW and have it shell out to run AI training.

But my IDE app requires the GTK3 suite, and I’d like to have it able to use OpenCV with Cuda so I thought perhaps I could trick Mingw into linking against the Visual studio built OpenCV. I got it to build and my only link errors are around cv::Error() and missing destructor/constructors. I tried feeding it the DLLs and the .libs built. I am thinking I could somehow get a .def file to possibly use this procedure (c++ - MinGW, linking to a dll on Windows - Stack Overflow) and get the mingw compiled/linked app to use the OpenCV with CUDA built by VS2022 (vc17)

I know the easy route is to recompile CV with Mingw, and technically I’d have two OpenCV builds but hopefully they would not conflict or pass objects across the boundry. This seems scarier than tweaking mingw’s LD to find the OpenCV constructors…

Now I am trying to re-architect things enough to get us onto windows. My other route is to try building more and more of the application with Visual studio, but I get stuck at the GDL/GDLMM situation where there are no Meson scripts and I can’t use autotools. I also had nightmares with M4 macro stuff.

I know there are various routes to go but I have an application that is massive and anything I try takes weeks and lots of $$$ to attempt. I know this is normally something you don’t do, but I am in a corner and need to do something ninja to make it work until I can better fix things.

Idea 1: Build OpenCV with both mingw and visual studio, hope no conflicts, deal with slower non-cuda CV in the GTK gui (mingw side).

Idea 2: Build OpenCV with VS2022, tweak the .lib/dlls to either static/dynamic link with mingws LD (I got close, only undefined constructor/destructor)

Idea 3: Build more of the application with VS2022, try to carve GTK/GDL stuff into a smaller library and reverse link it with .def files into Visual Studio’s build. MingW would build the library doing GTK only and visual studio builds the rest?

Idea 4: Try to move up to GTK4 where supposedly it builds on windows easily. $$$$ and lots and lots of time to even try. Only really mentioned to show I thought about it.

Idea 5: Dump GTK and move to QT which is likely even worse $$$ wise and requires new license deals likely with a company that used to be named “TrollTech” with a horrid reputation.

Idea 6: Dump CUDA and move to OpenCL, deal with slower AI training and someday Nvidia not supporting OpenCL on their cards. Build everything with MinGW and nothing with Visual Studio. (Requires rewriting my AI training code ugh)

I need some help. I know I am not “supposed” to mix these things. I am not using much beyond Mat and VideoReader/VideoWriter at the moment as we had to pull the Freetype code out when we ported to Mac. I cannot build everything entirely within one compiler. Thanks to mostly Nvidia since they think WSL is an option (No USB camera support, hard to manage files, networking latency with our low-level PLC interfaces) I am basically into a bad corner and need some help escaping.

Dependencies (not all but a lot):

  • Gtk3, gdk, gdkmm, gtkmm, gdlmm, pangocairo, gtksourceviewmm, gdk_pixbuf, giomm, harfbuzz, pangomm
  • OpenCV (Keeping CUDA enabled is the point of the exercise, we build contrib-trackers too)
  • OpenSSL, Postgresl, Sqlite, Boost


AI Trainer: (command line, needs CUDA, OpenCV, C-linkage)
AI IDE: (GTK3, needs OpenCV, shells out to run AI Training for Trianing, but also links against it’s C-interface for doing AI inside the IDE can change if we cannot link anymore )