c++ubuntug++c++23

g++ not finding <print> on Ubuntu


I'm running Ubuntu 24.04.2 LTS. g++ is not finding header file. #include give a fatal error: print: No such file or directory

3 | #include <print>
  |          ^~~~~~~

compilation terminated.

I've used:

g++ -I. -std=c++23 -std=gnu++23 *.cpp 

I've tried -std=c++23 and -std=gnu++23 alone as compiler arguments.

g++ --version says I have g++ 13.3.0
gcc --version says I have gcc 13.3.0

I've tried sudo apt remove g++23 and then sudo apt update and then sudo apt install build-essential.

sudo apt-cache search g++23 gives me nothing
sudo apt-cache search g++14 gives me clang-14
sudo apt-cache search g++17 gives me clang-17
sudo apt-cache search g++20 gives me some java and python file but no g++ or clang files.

I've event tried sudo apt install g++23 and even sudo apt-get install --reinstall cpp-23

From / I've tried sudo find . -name "print" -type f no files found.

Nothing above has worked.

Here is my simple Cpp23HelloWorld.cpp program

#include <iostream>
#include <format>
#include <string>
#include <print>

using std::print;

int main(void)
{
   print("C++23 Hello World\n");

   return 0;
}

Note the unneeded includes just a sanity check that the compiler could find them.

What do I need to do to be able to compile a C++23 program? Or at the least be able to use #include in my program?


Solution

  • Per cppreferences's compiler support page, gcc 14 and higher support <print>.

    You have gcc 13.3 so it does not support that part of C++23.