make对于g ++不使用-std = c ++ 11选项 [英] make is not using -std=c++11 option for g++

查看:163
本文介绍了make对于g ++不使用-std = c ++ 11选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用make编译c ++文件.但是,默认情况下它不使用-std = c ++ 11标志.每当我需要编译使用c ++ 11特定功能的程序时,都必须使用g ++显式编译它.

I am trying to compile c++ files using make. But, it is not using -std=c++11 flag by default. Whenever I need to compile a program which uses c++11 specific features, I have to explicitly compile it using g++.

所以,我想问一下我如何让我的系统上的所有c ++文件自动使用-std = c ++ 11选项.

So, I want to ask how can I have make automatically use the option -std=c++11 for all my c++ files on my system.

如果我需要为g ++更改一些全局makefile,那么在Linux Mint 18上该makefile的位置是什么,需要更改或添加什么?

If I need to change some global makefile for g++ , what is the location of the makefile on Linux Mint 18 and what needs to be changed or added?

还是我需要为自己创建一个Makefile?

Or do I need to create a Makefile for myself?

我正在调用make,例如

EDIT 1: I am invoking make like

make myfile

在目录中只有.cpp文件及其二进制文件.目录中没有任何Makefile.

And there are only .cpp files and their binaries in the directory. I don't have any Makefile in the directory.

在这里, myfile 是我要编译的c ++文件的名称.

EDIT 2: Here, myfile is the name of the c++ file which I want to compile.

当我使用-d选项运行make时,我得到以下输出(我不能粘贴所有输出,因为它很长并且超过了主体尺寸的限制,所以我包括了输出的屏幕截图).图片1
而且此图片(2)从末尾开始有几行.
图片2

When I run make with the -d option, I get the following output (I can not paste all of the output as it is quite long and is exceeding the body size limit so, I am including the screenshots of the output). Image 1
And this image(2) has some lines from the end.
Image 2

我有意对文件"MagicalWord.cpp" 进行了更改,以便使make有所作为!

I intentionally made a change in the file "MagicalWord.cpp" so that make finds something to make!

推荐答案

没有全局makefile",也没有办法更改所有make调用的默认标志(除非您将源代码编辑为GNU make和自己编译,在这种情况下是个坏主意.

There is no "global makefile" and there is no way to change the default flags for all invocations of make (unless you edit the source code to GNU make and compile it yourself, which is a bad idea in this situation).

在您的makefile中,添加以下行:

In your makefile(s), add the line:

CXXFLAGS += -std=c++11

假设您正在使用内置规则来编译事物,或者您正在将标准变量与自己的规则一起使用,这将满足您的需求.

Assuming you're using the built-in rules for compiling things, or that you're using the standard variables with your own rules, that will do what you need.

如果这不起作用,我们将需要查看您的makefile或至少您用于构建C ++源文件的规则(如 -d 输出之类的内容在这里不起作用--如果没有构建文件(您认为应该是类似文件),那将很有趣.

If that doesn't work we'll need to see your makefile or at least the rules you use to build your C++ source files (things like the -d output aren't useful here--that would be interesting if files weren't being built, that you thought should be or similar).

这篇关于make对于g ++不使用-std = c ++ 11选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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