Currently I compile my code using the following command. g++ helloWorld.cpp, however this defaults to I believe c++98(MacOs commandlinetools). I want it to compile in c++17/20. I know you can use the command g++ -std=c++17 helloWorld.cpp, which then forces it to compile in c++17. However is there any way to change this behavior so that it is default? When I run the command clang --version i get
clang version 16.0.6
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-16/bin
clang 16 I know defaults to c++ 17, which will work for me, but when i run the command g++ --version i get the following. is there any way to change that?
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
this is the clang installed with apples commandlinetools, and the clang I have when I run clang --version, was installed using macports. Any help would be appreciated.
checking my clang version using the following command clang --version,
You have a few choices.
g++
on mac and use explicit path,alias g++=/path/to/clang++16
, org++
In last choice, write following snippet:
#!/bin/bash
g++ -std=c++17 "$*"
and place it under desired path (I name /path/to/wrap.bash
for description purpose) which will be reachable from $PATH
environment variable by following these steps:
$PATH
was set:
echo "$PATH"
/path/to
to $PATH
in your shell's setup script (~/.zshrc
or ~/.bash_profile
for locally; system-wide configuration is placed on different place):
export PATH="$PATH:/path/to"