1
votes

I installed gcc-9.3.0 in linux following the simple steps in https://gcc.gnu.org/wiki/InstallingGCC The installation was successful. I thought this process would install gmp and mpfr along the way. But I cannot find the gmp or mpfr libraries.

Should I install them when I do ./configure?

1
The webpage you link shows several versions (and discusses gmp+mpfr in details), which steps exactly did you follow? What kind of linux are you on, can't you just install gmp/mpfr with your package manager? Is gcc complaining that it is missing gmp/mpfr at runtime, or do you want gmp and mpfr for your own use in other programs?Marc Glisse
I followed the one on the bottom. gcc was successfully installed but I want gmp and mpfr for other use.enni707
Ah, yes, those instructions are for people who only care about gcc and don't want to use gmp/mpfr directly (only as a tool that gcc internally uses). You will need to install gmp and mpfr separately, either with your package manager, or following the instructions for each one on their own webpage (download, configure, etc).Marc Glisse
Thank you for your answer. In that case, should I install gmp and mpfr first, then install gcc?enni707
If you have a GMP that works, it would be a shame to throw it away. The answer depends on where you are installing things. If you install a dynamic version of GMP in a non-standard location and use that to build gcc, then, as explained on the gcc page, you may get into trouble with gcc not finding it at runtime.Marc Glisse

1 Answers

1
votes

There are two different ways you can provide GCC with prerequisite external host libraries like GMP and MPFR:

  1. Before configuring, run ./contrib/download_prerequisites from the toplevel GCC source directory. It will download the sources from the respective project repositories. That's all you have to do; GCC will configure and build these libraries before running configure for itself or its target libraries.

  2. configure with --with-gmp etc. to point to the place where the respective host library had been installed.

Either approach has its ups and down:

The first approach needs internet connection and build times go up. However the increase of build time is negligible to the build time needed for the rest of the compiler and its target libraries.

On the other hand, you will get the right version and build options of either host lib as preferred by GCC, irrespective of which lib version might already have been installed on the host. And this configuration is much more convenient and self-contained when you are cross-compiling GCC (because it's about host libraries, and you thus have to install the prerequisite libraries on the host; installing it on build is pointless). And it's more robust / self-contained if you are distributing the built compiler: If the intended host does not have GMP etc installed, then you'll have additional work to do on that host.

The second approach is more complicated because you have to build / install the prerequisites on the host; correct version, correct configure flags etc.

On the other hand, you only have to build the prerequisites once for each host. When you are configuring / rebuilding the compiler more than once, for example when you are doing GCC development, then it's a bit faster cycle.

In the first case, the lib versions are independent of the host versions of the libraries; GCC will actually not care whether the libs are present on the host because it is using it's own "copy". The libraries will be linked statically into the executable, hence you won't find them anywhere (Maybe GCC has the option to do shared in-tree builds for the libs, I don't know).

I am very much preferring the 1st approach because it is self-contained and easier, in particular because I am frequently building GCC as canadian cross, i.e. build ≠ host ≠ target ≠ build.