更改 g++ 中的默认 C++ 标准 [英] Change default C++ standard in g++

查看:36
本文介绍了更改 g++ 中的默认 C++ 标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了以 C++11 标准编译程序,我们需要做:

In order to compile a program in C++11 standard we need to do :

 g++ -std=c++11 myProgram.cpp -o myProgramExec

但是有没有可能我可以将 g++ 的默认标准设置为 C++11,这样我就不必一次又一次地提及这个选项虽然我也可以在我的 .bashrc 中为此添加一个别名:

But is it possible that i can set the default standard of g++ as C++11, so that i don't have to mention this option again and again Although i can also add an alias for this in my .bashrc :

alias g++='g++ -std=c++11';

但我想知道是否有比这更好的方法.是否有任何可以编辑的 g++ 配置文件来实现这一点?或者有更简单的方法吗?

But i wonder if there is any better way than this.Is there any config file of g++ which can be edited in order to achieve this? Or is there some easier way to do this?

推荐答案

经过一番研究(你可能自己已经做过了),我还没有找到改变 g++ 的默认行为的方法 除了重新构建自定义版本或为其设置别名.

After a bit of research (which you've probably already done yourself), I haven't found a way to change the default behavior of g++ other than rebuilding a custom version or aliasing it.

为什么这可能是件好事:

每个版本的 g++ 都有一个单一的、明确定义的默认行为,这一点很重要.考虑一下:如果您更改 g++ 的默认行为并尝试编译其作者不知道您的配置的 C++ 项目,则该项目可能无法编译或编译时出现细微的错误/意外行为.

It is important that each version of g++ has a single, well-defined default behavior. Consider this: if you change the default behavior of g++ and try to compile a C++ project whose author could not be aware of your configuration, the project may fail to compile or compile with subtle errors / unexpected behaviors.

在您自己的项目中,您可以轻松地将所有相关标志和选项添加到您的 MakefileCMakeLists.txt 中,这样您就无需再次键入它们.这也将确保编译您的项目的其他人将收到正确的选项,而不管他们的配置如何.

In your own project, you can easily add all the relevant flags and options to your Makefile or CMakeLists.txt so that you don't need to type them again. This will also ensure that other people compiling your project will receive the correct options regardless of their configuration.

这篇关于更改 g++ 中的默认 C++ 标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆