首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用llvm-11与gcc-11用-std=c++2a编译的标准库标头时出错

使用llvm-11与gcc-11用-std=c++2a编译的标准库标头时出错
EN

Stack Overflow用户
提问于 2022-03-16 10:34:08
回答 1查看 249关注 0票数 0

我试图与gcc标准库标题一起使用clang,如下所示:

代码语言:javascript
复制
/opt/rh/llvm-toolset-11.0/root/usr/bin/clang -MD -MF bazel-out/k8-fastbuild/bin/external/com_google_googletest/_objs/gtest/gtest-typed-test.d '-frandom-seed=bazel-out/k8-fastbuild/bin/external/com_google_googletest/_objs/gtest/gtest-typed-test.o' -iquote external/com_google_googletest -iquote bazel-out/k8-fastbuild/bin/external/com_google_googletest -isystem external/com_google_googletest/googlemock -isystem bazel-out/k8-fastbuild/bin/external/com_google_googletest/googlemock -isystem external/com_google_googletest/googlemock/include -isystem bazel-out/k8-fastbuild/bin/external/com_google_googletest/googlemock/include -isystem external/com_google_googletest/googletest -isystem bazel-out/k8-fastbuild/bin/external/com_google_googletest/googletest -isystem external/com_google_googletest/googletest/include -isystem bazel-out/k8-fastbuild/bin/external/com_google_googletest/googletest/include -isystem /opt/rh/devtoolset-11/root/usr/include/c++/11 -isystem /opt/rh/devtoolset-11/root/usr/include/c++/11/bits -isystem /opt/rh/devtoolset-11/root/include/c++/11/x86_64-redhat-linux/bits -fdiagnostics-color -Wfatal-errors '-std=c++2a' -Wall -Wno-sign-compare '--gcc-toolchain=/opt/rh/devtoolset-11/root' -Wheader-guard -pthread -c external/com_google_googletest/googletest/src/gtest-typed-test.cc -o bazel-out/k8-fastbuild/bin/external/com_google_googletest/_objs/gtest/gtest-typed-test.o

然后我得到了这个错误:

代码语言:javascript
复制
In file included from external/com_google_googletest/googletest/include/gtest/gtest.h:62:
In file included from external/com_google_googletest/googletest/include/gtest/internal/gtest-internal.h:40:
In file included from external/com_google_googletest/googletest/include/gtest/internal/gtest-port.h:395:
/opt/rh/devtoolset-11/root/usr/include/c++/11/bits/regex.h:56:9: fatal error: use of undeclared identifier 'regex_constants'
                      regex_constants::match_flag_type     __flags);

错误的原因是什么?gcc和克朗之间有不相容的地方吗?我应该安装clang和libc++吗?这是通过安装llvm软件包来实现的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-16 13:18:17

gtest-port.h文件包含一个带有#include <regex.h>的文件(有关代码,请参见这里 )。它期望文件是POSIX regex.h,它通常直接安装在前缀/usr/include下。正如您在错误消息中看到的那样,编译器尝试包含错误的/usr/include/c++/11/bits/regex.h文件。

.../bits/中的头文件不打算由用户代码直接包含。是标准库实现的内部。因此,直接包含它失败(丢失的符号可能在另一个内部头文件中定义)对我来说并不奇怪。

为了解决您的问题,我建议您尝试在编译命令中省略.../bits目录。我不知道是谁告诉您包含它们的,但是它们不应该添加到编译器搜索路径中。

*将这两个标志从编译器命令行中删除:

代码语言:javascript
复制
-isystem /opt/rh/devtoolset-11/root/usr/include/c++/11/bits
-isystem /opt/rh/devtoolset-11/root/include/c++/11/x86_64-redhat-linux/bits 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71495508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档