Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set global Clang flags?

I’m using Clang on MacOS. When I compile C++ with clang++, is there a way to specify -std=c++17 without writing it every time? Is there some sort of a global clang config file?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

alias c++="c++ -O2 -W -Wall -std=c++17"

You can add something like that to your bashrc or whatever shell you use.

Another thing that should work on MacOS, works on every other unix, would be to create a wrapper script in /usr/local/bin/. Assuming you have that in your $PATH. Otherwise the problem recurses to exetending your PATH.

% cat >> /usr/local/bin/c++ <<EOF
#!/bin/sh
/usr/bin/c++ -O2 -W -Wall -std=c++17 "$@"
EOF
% chmod a+x /usr/local/bin/c++

The cat creates the file and the chmod makes it executable by all. Use the text editor of your choice if you don’t understand that cat command.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading