I am facing an issue while using the gmp library:
> warning: implicit declaration of function ‘mpz_prevprime’; did you
> mean ‘mpz_nextprime’? [-Wimplicit-function-declaration]
>
> undefined reference to `mpz_prevprime' collect2: error: ld returned 1
> exit status
I've downloaded the gmp library (version 6.3.0) and installed it using MSYS this way (I've found the instructions in a tutorial):
cd gmp_folder
./configure
make
make check
make install
Then, I've included the library in my C file:
#include <gmp.h>
and also in my Makefile:
LDFLAGS = -lm -lgmp
What is strange is that the compiler seems to be able to find some functions but not this one. For example, the compiler does not complain if I change mpz_prevprime for mpz_nextprime.
Thank you for your help.
Appendix: perhaps the issue comes from my Makefile, see below:
CC = gcc
CFLAGS = -Wall -g
LDFLAGS = -lm -lgmp
INCLUDES = -I./
SRCS = ./*.c
MAIN = cryptography.exe
all: $(MAIN)
$(MAIN): $(SRCS)
$(CC) $(CFLAGS) $(SRCS) -o $(MAIN) $(LDFLAGS)
clean:
rm ./cryptography.exe
My folder hierarchy:
Main Folder
|
|-------- C files (sources + headers) of my own
|-------- Makefile
|-------- gmp subfolder
|
|-------- gmp files
EDIT & FIX:
the issue was GCC looking for another gmp library installed on my computer (I wasn't even aware of having it). I've specified the path on the correct gmp library (the one I've compiled):
In the Makefile, changing this line:
LDFLAGS = -lm -lgmp
for this one:
LDFLAGS = -lm -L./gmp_subfolder/.libs -lgmp
fixed my issue.