Hi all!
( I am very excited to use Zig to make fast image processing libraries and apps, but I’m not sure how to use Zig to import popular libraries like openCV or DarkNet. I have tons of questions about that, but I’ll try to ask small and specific questions. I have experience working with Python, but compiling these things is a real challenge for me, that’s why I created an account just today. )
So I have a dev Docker image with different compilers and dev libraries, on Ubuntu.
I cloned openCV and ran cmake + make using gcc and clang, no problems, hovever I can’t get it to compile in Zig.
Maybe I’m doing something very stupid.
Is there a better way to tell cmake how to use Zig?
( I actually tried to compile DarkNet with Zig in the same way, by defining the CC and CXX variables and I made it work all the way until the last step. )
I always thought that Zig is a drop-in replacement for Clang.
Suppose I want to make this work and compile openCV…
is there another flag that I can use to exclude those libraries ? or a flag to ignore the excluding of libraries ?
It was rejected, but I don’t understand why…
To me, it makes sense to be able to use Zig in the same way you would use clang, in a build process like cmake.
I suppose the idea is to rewrite all your build process in build.zig ? In the case of openCV, it looks like a massive task, so maybe there’s a better way ?
Sorry that you’re hitting a wall there - that’s a bummer. If I was in your position, I’d probably just build the cmake file and link it as whatever type of library it produces in Zig build. You can also add a step in build to run that cmake file directly. Here’s an example of adding a step to run a command on zig build:
You can change that out for your cmake commands so it would be like running cmake directly from the console. If memory serves, CMake caches stuff so I don’t know what the effect of running the same command multiple times has so I’d test that out. I have code written to detect if a file exists (such as a library file) if need be. Again, not a perfect solution, but it does work.
When you say import into Zig, I take it that you’re building a Zig front end for this stuff? I’m just trying to be clear about what you mean when you say import. If so, you’ll need to add a build step to link against the libraries.
Thank you for your answer @AndrewCodeDev !
I see what you mean.
I want to import C/C++ code in Zig so that I can (ideally) cross-compile a self contained CLI app. Basically I don’t want to ask users to install openCV so they can run my app.
I don’t have enough experience with compiling C languages and linking them. From what I understand from your answer, I could compile obj files with a different compiler then link them with Zig? Basically I could define some external functions in Zig and they would be found in the linking step? Not sure if that’s possible.