Makefile modification to support c++11

前端 未结 3 1337
后悔当初
后悔当初 2021-01-12 13:41

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 compla

相关标签:
3条回答
  • 2021-01-12 14:27

    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.

    0 讨论(0)
  • 2021-01-12 14:30

    You can keep it in multiple lines, but you probably want to append, not to assign:

    # e.g.
    CFLAGS  += -O3
    CFLAGS  += -std=c++0x
    CFLAGS  += -pg -D_DEBUG -g -c -Wall
    
    0 讨论(0)
  • 2021-01-12 14:34

    Where did you get that mess from? That makefile was wrong long before you modified it for C++11.

    Let's start with the first line:

    MACHINE = $(shell echo `uname -s`-`uname -m` | sed "s/ //g")
    

    Try running the command echo `uname -s`-`uname -m` and you'll see if has no spaces in anyway, so what's the point in the sed command?

    Maybe you want this:

    MACHINE = $(shell uname -s -m | sed "s/ /-/g")
    

    That only runs two processes (uname and sed) not four (two unames, echo and sed)

    If you're using GNU make it should be

    MACHINE := $(shell uname -s -m | sed "s/ /-/g")
    

    So it's only run once.

    CCC     = CC
    

    What is CC?

    CCC     = g++
    

    Oh, it doesn't matter, you've replaced the value anyway. The conventional make variable for the C++ compiler is CXX

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

    As others have pointed out, you set CFLAGS, then set it to something different, then to something different. Only the last value will be kept.

    LFLAGS  = -O
    LFLAGS  = -pg -g
    

    Same here, and what is LFLAGS? Do you mean LDFLAGS?

    A good way to debug makefiles is to create a target to print out the variables you are setting, to check they have the values you expect:

    print-vars:
            echo CFLAGS is $(CFLAGS)
            echo LDFLAGS is $(LDFLAGS)
    
    0 讨论(0)
提交回复
热议问题