我正在嘗試將 clang 與 gcc 標準庫頭一起使用,如下所示:
/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
然后我得到這個錯誤:
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之間是否不兼容?我應該安裝 clang 頭檔案和 libc 嗎?是通過安裝包 llvm-dev 制作的嗎?
uj5u.com熱心網友回復:
該gtest-port.h檔案包含一個檔案#include <regex.h>(參見此處的代碼)。它期望檔案regex.h是通常直接安裝在前綴下的 POSIX /usr/include。正如您在錯誤訊息中看到的那樣,編譯器會嘗試包含/usr/include/c /11/bits/regex.h錯誤的檔案。
中的頭檔案.../bits/并不意味著用戶代碼直接包含。它們是標準庫實作的內部。因此,直接包含它失敗對我來說并不奇怪(丟失的符??號可能在另一個內部頭檔案中定義)。
為了解決您的問題,我建議您嘗試.../bits在編譯命令中省略目錄*。我不知道誰告訴你要包含它們,但它們并不意味著要添加到編譯器搜索路徑中。
* 從編譯器命令列中洗掉這兩個標志:
-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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/445353.html
