Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

c++ - How to reinstall gcc and g++ on ubuntu linux

I think there may be something wrong with my gcc and g++ install because this code below will not run on my computer.

#include <iostream>
#include <numbers>

int main()
{
    long double pi {0};
    long double pi2 {0};

    pi  = std::numbers::pi_v<long double>;
    pi2 = std::numbers::pi_v<long double>;

    std::cout << pi << std::endl << pi2;

}

How can I do a full reinstall on gcc and g++? Also, how do I make sure CodeBlocks is using this reinstalled version.

EDIT: running g++ version 11.1.0 & using the -std=c++20 this is the error message that appears:

g++ randomCodeWhileReading.cpp -o -std=c++20
randomCodeWhileReading.cpp: In function ‘int main()’:
randomCodeWhileReading.cpp:9:16: error: ‘std::numbers’ has not been declared
    9 |     pi  = std::numbers::pi_v<long double>;
      |                ^~~~~~~
randomCodeWhileReading.cpp:9:30: error: expected primary-expression before ‘long’
    9 |     pi  = std::numbers::pi_v<long double>;
      |                              ^~~~
randomCodeWhileReading.cpp:10:16: error: ‘std::numbers’ has not been declared
   10 |     pi2 = std::numbers::pi_v<long double>;
      |                ^~~~~~~
randomCodeWhileReading.cpp:10:30: error: expected primary-expression before ‘long’
   10 |     pi2 = std::numbers::pi_v<long double>;
      |                              ^~~~
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please: ALWAYS copy/paste your error message when you post a question!

I suspect this is the compile error you're getting:

x.cpp:2:10: fatal error: numbers: No such file or directory
 #include <numbers>

The header is only available since C++20: https://en.cppreference.com/w/cpp/numeric

Q: Do you have a C++20-compatible version of G+? You can determine this using g++ --version

Q: Are you compiling for C++ 20 (e.g. -std=c++20)?

Here is the Gnu C++ documentation for C++ 20 compatibility:

https://gcc.gnu.org/projects/cxx-status.html

C++20 Support in GCC GCC has experimental support for the latest revision of the C++ standard, which was published in 2020.

C++20 features are available since GCC 8. To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line. Or, to enable GNU extensions in addition to C++20 features, add -std=gnu++20.

Important: Because the ISO C++20 standard is very recent, GCC's support is experimental.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...