Need Help in installing latest C++ version on Ubuntu please

Pages: 12
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.

That is the error. Those three libraries are not found from your system.

Actually, the libraries are probably in two packages, something like "gmp" and "gmp-dev".
You might have the first installed, because it has the "so" that already compiled executables link to at runtime.
However, for compiling you do need the header files of the library that are typically in *-dev -named packages (in Debian/Ubuntu, AFAIK).

You have to check what are the names of the GMP, MPFR, and MPC packages in your Ubuntu, and whether they have sufficient version. If sufficient, then install also the corrsponding dev packages.

If your Ubuntu does have only older version, then you would have to first do source installs of these libraries before you can build GCC.


kigar64551 told that Debian has GCC 12 packages in some repo. Perhaps someone has already third-party repo with GCC 12 in it for your version of Ubuntu? That would be clearly simpler solution than a source build.
(I have never understood how Ubuntu repos are set up.)


The make -j4 is not magic. It is simply running program make with option -j that takes parameter 4.
The option -j tells to start multiple instances (here you say "4") of compiler to compiler translation units in parallel.

The make reads instructions -- what it should do -- from Makefile that was created by the configure script.
The plain "make" compiles "default target" from Makefile.
The "make install" compiles target "install" from Makefile (but if the default target is not built yet, then that is built first, before the "install").
In fact, Ubuntu 22.04 (i.e. the current "LTS" release) does have GCC 12 packages in the official "standard" package repositories.

Event though the "default" GCC version on Ubuntu 22.04 still is 11.

Just run apt install gcc-12, instead of apt install gcc to install GCC 12. The same goes for g++-12 and friends.

Then you can use gcc-12 and g++-12 commands.
Last edited on
Hello @keskiverto and @kigar64551

I have upgraded from Ubuntu 20.04 LTS to Ubuntu 22.04 using website:
https://itsfoss.com/upgrade-ubuntu-version/



Then used your sudo apt install g++-12 commands.

Many Thanks for excellent help.

Best regards,
Last edited on
Prof_CPP_Marc_Ed5/Code/c01_code/01_HelloWorld$ cat helloworld.cpp

1
2
3
4
5
6
7
8
9
// helloworld.cpp

import <iostream>;

int main()
{
	std::cout << "Hello, World!" << std::endl;
	return 0;
}


Prof_CPP_Marc_Ed5/Code/c01_code/01_HelloWorld$

g++-12 -std=c++20 -fmodules-ts -o hello helloworld.cpp


Above command is giving following errors:


In module imported at helloworld.cpp:3:1:
/usr/include/c++/12/iostream: error: failed to read compiled module: No such file or directory
/usr/include/c++/12/iostream: note: compiled module file is ‘gcm.cache/./usr/include/c++/12/iostream.gcm’
/usr/include/c++/12/iostream: note: imports must be built before being imported
/usr/include/c++/12/iostream: fatal error: returning to the gate for a mechanical issue
compilation terminated.
Last edited on
How to fix above compile error please?
Thanks
Change your line 3 to
#include <iostream>

You can go back to modules once you confirm that simpler things are working.
Last edited on
Visual Studio is quite notorious for doing that, having C/C++ extensions that work for only for Windows


gnu also has non-standard c++ extensions. eg:

1
2
3
4
5
6
7
8
9
10
11
#include <vector>
#include <concepts>

auto sum(const std::vector<auto>& vec) {
	return 0;
}

int main() {
	const std::vector vi {1, 2, 3};
	sum(vi);
}


which compiles OK with gcc but is 'non-conforming C++' according to MS.
https://godbolt.org/z/GahYMcaxP
I know VisualC++ ain't the only compiler that has extensions that aren't shared by other compilers.

The extensions can be so stealthily pervasive it makes trying to get ISO standard C/C++ compliance hard to do at times.

It doesn't help that code that should be ISO standard ain't seen as such, as your example shows seeplus.
@AlexCantor,

Sadly even the latest GCC, 12.2, isn't able to use (consume) modules. Nor do text formatting with <format>.

You have to use pre-C++20 #includes instead of imports. And #include <format> won't work, GCC can't find the header.

You could use the 3rd party {fmt} library if you want, it does what std::format can do. Plus a few things C++ stdlib <format> doesn't do at this time.

https://fmt.dev/latest/index.html
On Ubuntu 22.04, compiled and ran above helloworld.cpp program as shown below:

$ g++-12 -fmodules-ts -x c++-system-header iostream

$ ls -ltr
total 8
-r--r--r-- 1 owner owner 118 Aug 15 2020 helloworld.cpp
drwxrwxr-x 3 owner owner 4096 Sep 7 13:04 gcm.cache

$
$
$ g++-12 -fmodules-ts helloworld.cpp -o helloworld
$ ls -ltr
total 28
-r--r--r-- 1 owner owner 118 Aug 15 2020 helloworld.cpp
drwxrwxr-x 3 owner owner 4096 Sep 7 13:04 gcm.cache
-rwxrwxr-x 1 owner owner 16584 Sep 7 13:05 helloworld
$
$ ./helloworld
Hello, World!
Above compile commands are based on the information from the following book:

Page 714 of C++20 for Programmers by
Deitel and Deitel


Module support with GCC, starting with V11, is partial. Whatever partial support means. ::shrug::

https://en.cppreference.com/w/cpp/compiler_support/20

So not completely surprised a simple example might actually work. That doesn't mean other examples, likely using internal partition files, will work also.

I simply don't know since I don't use GCC.
Topic archived. No new replies allowed.
Pages: 12