0

I'm trying to compile a simple program from the terminal that utilizes the condition_variable class. Upon building, I get the following error:

This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

In researching this error here, I added the necessary flag to my make file, but I'm still getting the same error.

Here is my makefile:

CXX=        g++ $(CCFLAGS)
MAIN=       main.o
DATACLASS=  dataclass.o
OBJS =      $(MAIN) $(DATACLASS)

LIBS=       -pthread

CCFLAGS=    -g -std=c++11

all:        main

main:       $(MAIN) $(DATACLASS)
    $(CXX) -o main $(MAIN) $(DATACLASS) $(LIBS)

dataclass:  $(DATACLASS)
    $(CXX) -o dataclass $(DATACLASS) $(LIBS)

clean:
    rm -f $(OBJS) $(OBJS:.o=.d)

realclean:
    rm -f $(OBJS) $(OBJS:.o=.d) main


%.d:    %.cc
$(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< \
    | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
    [ -s $@ ] || rm -f $@'

include $(OBJS:.o=.d)

I'm sure I'm missing something small and stupid as I'm new to makefiles, but any help would be greatly appreciated.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
barrt051
  • 242
  • 3
  • 13
  • Try bringing `CCFLAGS= -g -std=c++11` before `CXX= g++ $(CCFLAGS)`. – MikeCAT Sep 21 '15 at 11:16
  • 1
    `CCFLAGS= -g -std=c++11` is set **after** your `CXX` variable. – πάντα ῥεῖ Sep 21 '15 at 11:18
  • 1
    Why did you use `CCFLAGS` instead of `CXXFLAGS`? I think using `CXXFLAGS` and not adding `$(CCFLAGS)` to `CXX` is better. – MikeCAT Sep 21 '15 at 11:23
  • I don't think there's anything called "conditional_variable". – Kerrek SB Sep 21 '15 at 11:24
  • Thanks for all the replies. So far, no luck. I modified the makefile in accordance with @MikeCAT's suggestion: CXXFLAGS= g++ -g -std=gnu++11 However, I'm still getting that same error... – barrt051 Sep 21 '15 at 11:31
  • 1
    @barrt051 Your target definitons are also wrong: `dataclass:` => `dataclass.o:` – πάντα ῥεῖ Sep 21 '15 at 11:42
  • @πάνταῥεῖ: Indeed. The default rule will be used to make `dataclass.o` and that doesn't include `CCFLAGS`. But note that `make` variables are normally lazily expanded (or recursively-expanded, as the manual calls it), so there is no problem with definition order. (In Gnu make you can use `:=` instead of `=` to force immediate expansion.) – rici Sep 21 '15 at 16:22

1 Answers1

2
  1. Rewrite CXX to CXX = g++
  2. Change CCFLAGS to CXXFLAGS = -g -std=c++11, and
  3. Rewrite your rules to $(CXX) $(CXXFLAGS) ....

$(CXX) $(CXXFLAGS) will then be replaced with g++ -g -std=c++11. This is more of a standard method for defining a makefile. Here is a snippet of the resulting makefile.

CXX = g++
MAIN = main.o
DATACLASS = dataclass.o
OBJS = $(MAIN) $(DATACLASS)

LIBS = -pthread

CXXFLAGS = -g -std=c++11

all: main

main: $(OBJS)
    $(CXX) $(CXXFLAGS) $? -o $@ $(LIBS)

As a side note, are you sure this rule should be defined as such?

dataclass: $(DATACLASS)
    $(CXX) $(CXXFLAGS) $? -o $@ $(LIBS)

Should the target not be dataclass.o or $(DATACLASS) and the prerequisite some other file?


Note: I've also included some make automatic variables to tidy up the makefile rules.

  • $? - is replaced by all prerequisites
  • $@ - is replaced by the target name
Toby Speight
  • 27,591
  • 48
  • 66
  • 103
IKavanagh
  • 6,089
  • 11
  • 42
  • 47