'gmp is missing while configuring building gdb from source

I am trying to build gdb from source, which version is 11.1. I have configured the GMP including path, but the configure script still report an error.

configure: error: GMP is missing or unusable

I copied the config log.

configure:10433: checking for libgmp
configure:10453: gcc -o conftest -g -O2      conftest.c -lncurses -lm -ldl  -lgmp >&5
conftest.c:53:17: fatal error: gmp.h: No such file or directory

My configure command is something like below.

configure --prefix=/home/xxx/ins/gdb_11 --with-gmp-include=/home/xxx/ins/gmp-6.2.1/include --with-gmp-lib=/home/xxx/ins/gmp-6.2.1/lib

What might the problem be?



Solution 1:[1]

From looking at GDB's configure script, I think the problem is that GDB is not picking up the --with-gmp-include and --with-gmp-lib configure flags. These flags are handled in the toplevel configure script and made available to each sub-component (GDB, binutils, ld, etc) through the environment, and it looks like GDB doesn't pick these up.

The easiest way to move forward will be to override CFLAGS and CXXFLAGS at configure time, like:

configure CFLAGS="-I/gmp/include/path -L/gmp/lib/path" CXXFLAGS="-I/gmp/include/path -L/gmp/lib/path"

--- Later Edit ---

Though the technique in this answer will work, the correct answer is given by jiang da.

Solution 2:[2]

You can use gdb's configure option:

  --with-libgmp-prefix="path to gmp"

Solution 3:[3]

Make sure you have libgmp-dev installed

My OS is ubuntu 20.04

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libgmp-dev
wget http://ftp.gnu.org/gnu/gdb/gdb-11.2.tar.gz
tar -xvzf gdb-11.2.tar.gz
./configure
make
sudo make install

Once you installed GDB, you can print GDB version to test whether it is installed correctly.
gdb --version img

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 ouflak
Solution 3 hiifong