[英]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.我有一些代码,我使用(旧的)Mersenne Twister 头文件来获得一个好的伪随机数生成器。
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
.问题是该代码使用
register
关键字(据我所知)在c++11
已弃用,并在c++17
引发错误。 I believe I am using the latter in the version of clang
I'm using on Mac OSX (10.14.6; Mojave).我相信我在 Mac OSX (10.14.6; Mojave) 上使用的
clang
版本中使用了后者。
The Makefile I am using is as thus:我使用的 Makefile 是这样的:
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:尽管在 makefile 开始编译
lindhard.c
使用-std=c++11
或-std=c++98
标志,如下所示:
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:每次使用
register
关键字时都会抛出错误:
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? -std
标志是否未应用于包含文件的预处理? Am I going about this the wrong way?我会以错误的方式解决这个问题吗?
@MadScientist and @idz were correct above. @MadScientist 和 @idz 在上面是正确的。 The key was that the root libraries when using
root-config --cflags --glibs
added the following:关键是使用
root-config --cflags --glibs
时的根库添加了以下内容:
-stdlib=libc++ -pthread -std=c++17 -m64 -I/usr/local/Cellar/root/6.24.04/include/root -L/usr/local/Cellar/root/6.24.04/lib/root -lGui -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -stdlib=libc++ -lpthread -lm -ldl
This came after my flag -std=c++98
and therefore overrode it.这是在我的标志
-std=c++98
,因此覆盖了它。
The solution here was to move the -std=c++98
to after the root-config
line.这里的解决方案是将
-std=c++98
移到root-config
行之后。
I suppose it was technically possible that some of the ROOT
code that I was using required c++17
and then I'm not sure if this could have been resolved.我想从技术上讲,我使用的某些
ROOT
代码可能需要c++17
,然后我不确定这是否可以解决。
But as it turns out I was using a portion of the ROOT
code base that was older and likely (though I'm still not sure) didn't have any upgrades requiring c++17
.但事实证明,我使用的
ROOT
代码库的一部分较旧并且可能(尽管我仍然不确定)没有任何需要c++17
升级。
If it did I suppose my only choice would have been to update my incompatible library, Mersenne, to be compatible with c++17
如果是这样,我想我唯一的选择就是更新我不兼容的库 Mersenne 以与
c++17
兼容
PS: I know that Mersenne Twister now is implemented in C++ standard code, but for reasons I had preferred to use my old implementation. PS:我知道 Mersenne Twister 现在是用 C++ 标准代码实现的,但出于某些原因,我更喜欢使用我的旧实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.