Makefile修改支持c ++ 11 [英] Makefile modification to support c++11

查看:243
本文介绍了Makefile修改支持c ++ 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用gcc和-std = c ++ 0x选项编译单个文件。但我不能这样做通过makefile。这里是我的makefile中的标志集(其中后,抱怨关于c ++ 11关键字):

  MACHINE = $ shell echo`uname -s`-`uname -m` | seds / // g)
CCC = CC
CCC = g ++
CFLAGS = -O3
CFLAGS = -std = c ++ 0x
CFLAGS = -pg -D_DEBUG -g -c -Wall
LFLAGS = -O
LFLAGS = -pg -g



我缺少什么?



编辑
我把它改成了以下,但是我仍然得到编译错误,我不能通过命令行gcc调用。

  CXXFLAGS = -O3 -std = c ++ 0x -pg -D_DEBUG -g -c -Wall 


解决方案

这样你的makefile将使用你所有的 CFLAGS

  CFLAGS = -O3 -std = c ++ 0x -pg -D_DEBUG -g -c -Wall 

您正在使用每个CFLAGS = ...声明覆盖它们。



此外, c $ c> CXXFLAGS ,而不是 CFLAGS CFLAGS 适用于C应用程式。



正如@Florian Sowade所说,您可以使用 CFLAGS + = -O3 -std .... (或CXXFLAGS ..),以便用户可以在执行make时提供自己的标志。


I am able to compile a single file using gcc with -std=c++0x option. But I can't do this through makefile. Here are the set of flags in my makefile (which after make complains about c++11 keywords):

MACHINE = $(shell echo `uname -s`-`uname -m` | sed "s/ //g")
CCC     = CC
CCC     = g++
CFLAGS  = -O3
CFLAGS  = -std=c++0x
CFLAGS  = -pg -D_DEBUG -g -c -Wall
LFLAGS  = -O
LFLAGS  = -pg -g

What am I missing?

Edit: I changed it to the following, but I still get compile errors, which I don't get with command line gcc invocation.

CXXFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall

解决方案

This way your makefile will use all of your CFLAGS:

CFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall

You're overriding them with each "CFLAGS=..." declaration.

Moreover, it should be CXXFLAGS, not CFLAGS. CFLAGS is for C applications.

As @Florian Sowade said, you could use CFLAGS += -O3 -std.... (or CXXFLAGS..), so that users can provide their own flags when executing make.

这篇关于Makefile修改支持c ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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