vendredi 11 décembre 2020

What is the correct way to tell compiler to use c++ 11 within my makefile?

I am using g++ compiler, but it is defaulting to C++98 standard. I want to tell it to use C++11 within my makefile. The first few lines of my makefile are:

CXX=g++
CXXFLAGS=-std=c++11
ROOT_FLAGS=`root-config --cflags --libs `
G4_FLAGS=`geant4-config --cflags --libs`

GSL_FLAGS=-lgsl

Where I define the script target to compile I have:

bin/new_sum_pdfs: new_sum_pdfs.cc $(LIB)
    mkdir -p bin
    $(CXX) $(CXXFLAGS)  new_sum_pdfs.cc -I$(INC_DIR) -I$(OXSX_INC) -w -L$(LIB_DIR) -L$(OXSX_LIB_DIR) -l$(LIB_NAME) -l$(OXSX_LIB_NAME)  $(ROOT_FLAGS) $(G4_FLAGS) $(H5_LIBS) -larmadillo -o $@

The output of g++ --version is:

g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

So, I have defined the CXXFLAGS and I am giving it to the compiler, the output of running make is:

mkdir -p bin
g++ -std=c++11  new_sum_pdfs.cc -Isrc -I/home/hunt-stokes/oxo/include -w -Llib -L/home/hunt-stokes/oxo/build  -lbbfit -loxsx  `root-config --cflags --libs ` `geant4-config --cflags --libs` -lhdf5_hl_cpp -lhdf5_cpp -lhdf5_hl -lhdf5 -larmadillo -o bin/new_sum_pdfs

However, I am getting loads of errors, such as:

error: in C++98 ‘slice’ must be initialized by constructor, not by ‘{...}’

And others for using auto types and range-based for loops.

Note: The makefile works fine when I don't try to use C++ 11 standard things, I just really want to use C++11 and it doesn't seem to register the -std=c++11 flag! What am I missing?

Aucun commentaire:

Enregistrer un commentaire