I am learning to program in Zig and would like to use the GMP library for arbitrary precision numbers. I have the GMP library installed on my computer, and when I need to compile a program in C, I use the command:
gcc -o test test.c -I/opt/homebrew/Cellar/gmp/6.3.0/include/ -L/opt/homebrew/Cellar/gmp/6.3.0/lib/ -lgmp
but the program did not compile.
What changes do I need to make to build.zig for the program to compile? Could someone give a working example of some Zig code that uses the GMP library?
As I said, I am learning to program in Zig.
I would like to use the GMP library because I want to create some math programs (for example, calculate the number PI with an arbitrary number of digits or generate a list of prime numbers). This would serve as an incentive to learn a new language, but perhaps I should worry about learning the basics first.
The test program didn’t work because obviously it’s not enough to include @cImport({@cInclude(“gmp.h”);}) in main.zig. I tried modifying build.zig following some tutorials (A Simple Example of Calling a C Library from Zig · mtlynch.io, https://www.youtube.com/watch?v=HGlTuDmotnU&t=615s), but I was unsuccessful.
I haven’t done anything yet. I’m trying to call the GMP library first. There’s no point in starting to code anything if I can’t even call the library. My question is about how to call the GMP library, and I am asking for a basic, functional example.