Last active
July 12, 2023 13:38
-
-
Save gabonator/acb665922ef6c96db9211d6e8db22a9a to your computer and use it in GitHub Desktop.
gcc check standard version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requesting c++20 standard in gcc commandline does not ensure that it is supported or will be used, | |
# dumping the __cplusplus reveals that gcc completely ignores this request without any warning or error | |
# Such problems leads to similar error messages: | |
# main.cpp:1:24: error: ‘bit_cast’ is not a member of ‘std’; did you mean ‘bad_cast’? | |
# | |
# | |
# This shell script prints | |
# #define __cplusplus 202002L | |
# or | |
# #define __cplusplus 201709L | |
# depending on the version of gcc | |
# | |
# in my case `gcc --version` reports following | |
# gcc (Ubuntu 10.4.0-4ubuntu1~22.04) 10.4.0 | |
# vs | |
# gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0 | |
# | |
# To switch to gcc version 12 and update the gcc/g++ aliases, install more recent version and switch to it: | |
# sudo apt-get install g++-12 gcc-12 | |
# sudo update-alternatives --remove-all g++ | |
# sudo update-alternatives --remove-all gcc | |
# sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 50 | |
# sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 50 | |
# | |
# check alias for g++: | |
# sudo update-alternatives --get-selections | grep g++ | |
g++ -std=c++20 -dM -E -x c++ /dev/null | grep -F __cplusplus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment