mardi 19 octobre 2021

clang ignores -std=c++11 flag for include files

I have some code that I use a (old) Mersenne Twister header file with to get a good pseudo-random number generator.

The problem is that that code uses the register keyword which (as far as I understand) was deprecated in c++11 and throws an error with c++17. I believe I am using the latter in the version of clang I'm using on Mac OSX (10.14.6; Mojave).

The Makefile I am using is as thus:

BUILDDIR=$(TOPDIR)/bin
INCDIROUT=$(BUILDDIR)/include
LIBDIROUT=$(BUILDDIR)/lib
INCDIR=inc/
SRCDIR=src/
INCFLAG= -IMersenne -Iinc
LIBFLAG= -L. -L$(LIBDIROUT)

#need to use an older version of gcc b/c of Mersenne Twister using the deprecated `register` keyword
#https://github.com/danini/graph-cut-ransac/issues/23
CXX=clang++
#CXXFLAGS=-g -std=c++11 -Wall -pedantic
CXXFLAGS=-fpermissive -std=c++98

#trick for getting the git version in the code
GIT_VERSION = $(shell sh -c 'git describe --abbrev=4 --always')

CFLAGS += -D__GIT_VERSION=\"$(GIT_VERSION)\"

RUN_SCRIPT := $(shell mkdir -p 'bin/lib')

all: $(BUILDDIR)/realizeCascades $(LIBDIROUT)/rootUtil.o $(LIBDIROUT)/edepmath.o $(LIBDIROUT)/cascadeProd.o $(LIBDIROUT)/isotope_info.o $(LIBDIROUT)/weisskopf.o $(LIBDIROUT)/lindhard.o $(LIBDIROUT)/libncap.so

$(LIBDIROUT)/isotope_info.o: $(SRCDIR)/isotope_info.c $(INCDIR)/isotope_info.h
        $(CXX) -std=c++98 -fPIC -c $(CFLAGS) $(INCFLAG) $(SRCDIR)/isotope_info.c `root-config --cflags --glibs` $(LIBFLAG) 
        mv isotope_info.o $(LIBDIROUT)/

$(LIBDIROUT)/rootUtil.o: $(SRCDIR)/rootUtil.c $(INCDIR)/rootUtil.h
        $(CXX) -std=c++98 -fPIC -c $(CFLAGS) $(INCFLAG) $(SRCDIR)/rootUtil.c `root-config --cflags --glibs` $(LIBFLAG) 
        mv rootUtil.o $(LIBDIROUT)/

$(LIBDIROUT)/edepmath.o: $(SRCDIR)/edepmath.c $(INCDIR)/edepmath.h
        $(CXX) -std=c++98 -fPIC -c $(CFLAGS) $(INCFLAG) $(SRCDIR)/edepmath.c `root-config --cflags --glibs` $(LIBFLAG) 
        mv edepmath.o $(LIBDIROUT)/

$(LIBDIROUT)/weisskopf.o: $(SRCDIR)/weisskopf.c $(INCDIR)/weisskopf.h
        $(CXX) -std=c++98 -fPIC -c $(CFLAGS) $(INCFLAG) $(SRCDIR)/weisskopf.c `root-config --cflags --glibs` $(LIBFLAG) 
        mv weisskopf.o $(LIBDIROUT)/

$(LIBDIROUT)/lindhard.o: $(SRCDIR)/lindhard.c $(INCDIR)/lindhard.h
        $(CXX) -std=c++98 -fPIC -c $(CFLAGS) $(INCFLAG) $(SRCDIR)/lindhard.c `root-config --cflags --glibs` $(LIBFLAG) 
        mv lindhard.o $(LIBDIROUT)/

$(LIBDIROUT)/cascadeProd.o: $(SRCDIR)/cascadeProd.c $(INCDIR)/cascadeProd.h
        $(CXX) -std=c++98 -fPIC -c $(CFLAGS) $(INCFLAG) $(SRCDIR)/cascadeProd.c `root-config --cflags --glibs` $(LIBFLAG) 
        mv cascadeProd.o $(LIBDIROUT)/

$(LIBDIROUT)/libncap.so: $(LIBDIROUT)/isotope_info.o $(LIBDIROUT)/weisskopf.o $(LIBDIROUT)/lindhard.o $(LIBDIROUT)/cascadeProd.o $(LIBDIROUT)/edepmath.o $(LIBDIROUT)/rootUtil.o
        $(CXX) -std=c++98 -fPIC -shared $(LIBDIROUT)/lindhard.o $(LIBDIROUT)/weisskopf.o $(LIBDIROUT)/isotope_info.o $(LIBDIROUT)/cascadeProd.o $(LIBDIROUT)/edepmath.o $(LIBDIROUT)/rootUtil.o `root-config --cflags --glibs` -o $(LIBDIROUT)/libncap.so 

$(BUILDDIR)/realizeCascades: $(LIBDIROUT)/libncap.so $(BUILDDIR)/realizeCascades.cpp
        $(CXX) -std=c++98 -fPIC -Wl,-rpath=$(LIBDIROUT) $(CFLAGS) $(INCFLAG) $(LIBFLAG) $(BUILDDIR)/realizeCascades.cpp `root-config --cflags --glibs` -lncap -o $(BUILDDIR)/realizeCascades 

clean:
        rm -f $(LIBDIROUT)/*.o
        rm -f $(LIBDIROUT)/*.so
        rm -f $(BUILDDIR)/realizeCascades
        rm -f *.o
        rm -f *.so
        rm -rf $(LIBDIROUT)

despite using the -std=c++11 or -std=c++98 flags once the makefile begins to compile lindhard.c as thus:

clang++ -std=c++98 -fPIC -c -D__GIT_VERSION=\"v1.0.6-73-g01bc\"
-IMersenne -Iinc src//lindhard.c `root-config --cflags --glibs` -L. -L/Users/villaa/nrCascadeSim/bin/lib

An error is thrown for each of the many times the register keyword is used:

Mersenne/MersenneTwister.hh:187:2: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
        register uint32 s1;
        ^~~~~~~~~

I am struggling to find out the reason for this. Is the -std flag not being applied to the pre-processing of include files? Am I going about this the wrong way?

Aucun commentaire:

Enregistrer un commentaire