你这个问题比较简短,我分几种常见“Linux 下 C++ 配置版本”的场景来说明,你看看是哪一类,或者直接告诉我你具体想干啥。
g++ --version
或
g++ -v
clang++ --version
g++ main.cpp -std=c++17 -o main
常见选项:
-std=c++11-std=c++14-std=c++17-std=c++20-std=c++2b(实验性 C++23)set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
sudo apt install g++-9 g++-11 g++-12
update-alternatives 管理版本sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 110
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 120
切换版本:
sudo update-alternatives --config g++
export CXX=g++-12
cmake -S . -B build
或在 CMake 中:
set(CMAKE_CXX_COMPILER g++-12)
echo | g++ -dM -E -x c++ - | grep __cplusplus
输出示例:
201103L → C++11201402L → C++14201703L → C++17比如:
可以告诉我具体是什么库或什么报错,我可以给你更精确的方法。
我可以一步一步帮你配。