【发布时间】:2018-06-24 01:11:50
【问题描述】:
上下文
我正在开发一个需要英特尔 anaconda 发行版的项目,我们使用 googletest 来测试我们的本地人。我正在为我的编译器使用 clang。当我通过cmake 构建googletest 时,我得到了这个:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-all.cc:39:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/gtest.h:58:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/internal/gtest-internal.h:39:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/internal/gtest-port.h:452:
In file included from /foo/anaconda3/envs/idp3/include/regex.h:4:
/foo/anaconda3/envs/idp3/include/tclInt.h:60:16: error: typedef redefinition with different types
('int' vs 'long')
typedef int ptrdiff_t;
Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include/stddef.h:51:26: note: previous definition is here
typedef __PTRDIFF_TYPE__ ptrdiff_t;
我对问题的理解
clang/9.1.0 和 google-test 在 ptrdiff_t 上存在 typedef 冲突,其中 google 包含 regex.h,其中包含 conda 自己的 tclInt.h,它具有 typedef。 tclInt.h 由我们需要的 conda intel 频道包安装。卸载它会将mkl 和tbb 降级回各种版本。
这是一个绘制得很糟糕的依赖关系图,它显示了(我认为)typdef 发生的位置:
project native tests <-- googletest <-- regex.h <-- tclInt.h "typedef ptrdiff_t int;"
^
|
stddef.h "typedef ptrdiff_t long" (from clang)
我不太确定如何解决这个 typedef 冲突问题并解开它。一种替代方法是使用 gcc-8,但即使我运行 make 以使用导出的环境变量构建 googletest:
CXX=g++-8
CC=gcc-8
tclInt.h 标头仍从 clang 文件夹中提取,如我附加的错误转储中所示。
解决方法(?)
肯定还有其他我缺少的选项,但解决此问题的一种可能方法是使用没有此问题的 tclInt.h,或者 gcc-8 可能有一组包含标题'不要定义ptrdiff_t,我可以做一些事情来指向那个编译器。
注意:我可能大错特错,但这是我的假设。任何帮助表示赞赏。
如果有人想查看整个堆栈跟踪,请看这里:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-all.cc:39:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/gtest.h:58:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/internal/gtest-internal.h:39:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/internal/gtest-port.h:452:
In file included from /foo/anaconda3/envs/idp3/include/regex.h:4:
/foo/anaconda3/envs/idp3/include/tclInt.h:60:16: error: typedef redefinition with different types ('int' vs 'long')
typedef int ptrdiff_t;
^
/Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include/stddef.h:51:26: note: previous definition is here
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-all.cc:45:
/foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-port.cc:597:10: error: use of undeclared identifier 'regexec'
return regexec(&re.full_regex_, str, 1, &match, 0) == 0;
^
/foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-port.cc:606:10: error: use of undeclared identifier 'regexec'
return regexec(&re.partial_regex_, str, 1, &match, 0) == 0;
^
/foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-port.cc:619:15: error: use of undeclared identifier 'regcomp'
is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0;
^
/foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-port.cc:630:17: error: use of undeclared identifier 'regcomp'
is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;
^
5 errors generated.
【问题讨论】:
标签: c++ gcc cmake clang googletest